Skip to main content

Like Pushkin, but he subscribe to GCM/FCM and receive notifications

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pullkin-0.2.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pullkin-0.2.1-py2.py3-none-any.whl (17.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pullkin-0.2.1.tar.gz.

File metadata

  • Download URL: pullkin-0.2.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.26.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.6

File hashes

Hashes for pullkin-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f392aab074bac8ab8d6b8fa6d2457d5b52908168c8f3027928e9bc1b416f92f8
MD5 6514c446f2362542e82e3db132996604
BLAKE2b-256 7521438c07f6e8af833c2d58ffa0b252ad32ec637870b4bb1d0acba5926bb97e

See more details on using hashes here.

File details

Details for the file pullkin-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pullkin-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.26.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.6

File hashes

Hashes for pullkin-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bc2b960f454969eb956808bbb14856a0ad317f6ab93d8ffa0fb51eb251572d6a
MD5 d68d415e71108150db05a1ac7a686448
BLAKE2b-256 438492e024e7199f0d9ef22666ac21ccc57e40df34ff5a5f39dac436ad3aa867

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page