subscribe to GCM/FCM and receive notifications
python implementation of https://github.com/MatthieuLemoine/push-receiver
tested on python 2.7.16, 3.4.10 and 3.7.5
I put this together in a day or so, it’s still rough around the edges, especially the listen part, which I don’t really use myself and have just implemented for fun and only briefly tested
note that for the listening part I had to pull in http-ece which depends on a full blown native crypto library rather than just oscrypto. it is an optional dependency so you’ll have to install it explicitly by depending on push_receiver[listen]
usage
pip install push_receiver[listen,example]
basic usage example that stores and loads credentials and persistent ids and prints new notifications
you can also run this example with this command (change the sender id)
python -m "push_receiver" --sender-id=722915550290
from push_receiver import register, listen
import json
def on_notification(obj, notification, data_message):
idstr = data_message.persistent_id + "\n"
# check if we already received the notification
with open("persistent_ids.txt", "r") as f:
if idstr in f:
return
# new notification, store id so we don't read it again
with open("persistent_ids.txt", "a") as f:
f.write(idstr)
# print notification
n = notification["notification"]
text = n["title"]
if n["body"]:
text += ": " + n["body"]
print(text)
if __name__ == "__main__":
SENDER_ID = 722915550290 # change this to your sender id
try:
# already registered, load previous credentials
with open("credentials.json", "r") as f:
credentials = json.load(f)
except FileNotFoundError:
# first time, register and store credentials
credentials = register(sender_id=SENDER_ID)
with open("credentials.json", "w") as f:
json.dump(credentials, f)
print("send notifications to {}".format(credentials["fcm"]["token"]))
with open("persistent_ids.txt", "a+") as f:
received_persistent_ids = [x.strip() for x in f]
listen(credentials, on_notification, received_persistent_ids)
Metadata
Release files for push-receiver 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| push_receiver-0.1.1.tar.gz | 15.9 kB | Without provenance | Details for push_receiver-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| push_receiver-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for push_receiver-0.1.1-py2.py3-none-any.whl |
Total release size: 33.2 kB
Release files / push_receiver-0.1.1.tar.gz
| Download URL | push_receiver-0.1.1.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e49e6adadfd41f03e3a0ad1c732832db90fb9c5bcce0747ab3e451909f360ec
|
|
BLAKE2b-256 checksum How to use checksums |
75983722c171b49980f33291e6f83ffd7224c30bbe06419501a4c180ad4ec736
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
|
Release files / push_receiver-0.1.1-py2.py3-none-any.whl
| Download URL | push_receiver-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b16eebb79a04cf2e85ade8208df909566abded4095bae9936cefad87321a3fcd
|
|
BLAKE2b-256 checksum How to use checksums |
f27da3c15baccf427796f517f18427bc084aabf61dc82b3915ea226461d26de7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
|
Security for push-receiver 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.