Last active
December 11, 2021 23:36
-
-
Save sophieforceno/2fc7447ddcd1aa951852079e376aa93e to your computer and use it in GitHub Desktop.
Send push notifications to mobile devices using Simplepush API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
# Send push notifications to your mobile device | |
# using the Simplepush API | |
# | |
# Usage: spush.py title body eventid | |
# Accepts input from stdin | |
# e.g. sudo tail /var/log/somelog.log | spush.py title eventid | |
# by Sophie Forceno | |
# | |
import select | |
import sys | |
from simplepush import send, send_encrypted | |
body = "" | |
# Don't wait for stdin if there is none | |
if select.select([sys.stdin], [], [], 0.0)[0]: | |
for line in sys.stdin: | |
body += line | |
if len(body) == 0: | |
title = sys.argv[1] | |
body = sys.argv[2] | |
event = sys.argv[3] | |
else: | |
title = sys.argv[1] | |
# body from stdin | |
event = sys.argv[2] | |
# Send encrypted notification | |
try: | |
# API key, password, salt, title, body, event | |
send_encrypted("<Insert API key>", "<Insert password>", "<Insert salt>", title, body, event) | |
except: | |
print("Push notification failed.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment