pullkin


Namepullkin JSON
Version 0.14.0 PyPI version JSON
download
home_pagehttps://github.com/WhiteApfel/pullkin
SummarySubscribe to GCM/FCM and receive notifications like an android app
upload_time2024-02-26 15:50:42
maintainer
docs_urlNone
authorWhiteApfel
requires_python
licenseMozilla Public License 2.0
keywords fcm gcm push notification receive firebase google
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pullkin

[![CodeFactor](https://www.codefactor.io/repository/github/whiteapfel/pullkin/badge/master)](https://www.codefactor.io/repository/github/whiteapfel/pullkin/overview/master)
[![Build Status](https://app.travis-ci.com/WhiteApfel/Pullkin.svg?branch=master)](https://app.travis-ci.com/WhiteApfel/Pullkin)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pullkin)
![GitHub](https://img.shields.io/github/license/whiteapfel/pullkin)
![GitHub last commit](https://img.shields.io/github/last-commit/whiteapfel/pullkin)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pullkin)

Like Pushkin, but subscribe to FCM (GCM) and receive notifications

My alternative implementation 
of [python implementation](https://github.com/Francesco149/push_receiver) 
of [JS implementation](https://github.com/MatthieuLemoine/push-receiver)

Tested on python (3.6, 3.8, 3.10, pypy3.7-7.3.5)

I almost didn't write anything to consider it my intellectual property, 
just wrapped the code already written by Franc[e]sco in a design convenient for my own use 

Note that for the listening part Franc[e]sco has 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 `pullkin[listen]`

## Differences

* Add async listener
* Add async listener-coroutine
* Replace functions with class of listener

## Usage

### Installation

```shell
pip install pullkin
```

### How to use

```python
import json
import os.path
import asyncio

from pullkin import Pullkin
from pullkin.models import Message, AppCredentials
from pullkin.proto.mcs_proto import DataMessageStanza

SENDER_ID = '<<SENDER_ID>>'  # '1234567890'
# ANOTHER_SENDER_ID = '<<SENDER_ID>>'  # '1234567890'
APP_ID = '<<APP_ID>>'  # '1:1234567890:android:abcdef1234567890'
API_ID = '<<API_ID>>'  # 'AIzaSyDce4zFw4CqLqW2eCOqTbXfDx9a8mRnLpI'
FIREBASE_NAME = '<<FIREBASE_NAME'  # 'pullkin-example'
APP_NAME = '<<APP_NAME>>'  # 'cc.pullkin.example'

#
ANDROID_CERT = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'  
# 'da39a3ee5e6b4b0d3255bfef95601890afd80709' is default hash

pullkin = Pullkin()

if not os.path.exists('.persistent_ids.txt'):
    with open('.persistent_ids.txt', 'w+') as f:
        ...

with open(".persistent_ids.txt", "r") as f:
    received_persistent_ids = [x.strip() for x in f]


@pullkin.on_notification()
async def on_notification(message: Message, data_message: DataMessageStanza):
    idstr = data_message.persistent_id + "\n"
    with open(".persistent_ids.txt", "r") as f:
        if idstr in f:
            return
    with open(".persistent_ids.txt", "a") as f:
        f.write(idstr)
    print(message.notification)


async def main():
    if not os.path.exists('.pullkin_app_credentials'):
        with open('.pullkin_app_credentials', 'w+') as f:
            credentials = await pullkin.register(SENDER_ID, APP_ID, API_ID, FIREBASE_NAME, ANDROID_CERT,  APP_NAME)
            f.write(json.dumps(credentials.model_dump(mode="json")))
    else:
        with open('.pullkin_app_credentials', 'r') as f:
            credentials = AppCredentials.model_validate(json.loads(f.read()))
    
    await pullkin.add_app(sender_id=SENDER_ID, credentials=credentials, persistent_ids=received_persistent_ids)
    # await pullkin.add_app(sender_id=ANOTHER_SENDER_ID, credentials=another_credentials, persistent_ids=another_received_persistent_ids)
    
    
    await pullkin.run()


asyncio.run(main())
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/WhiteApfel/pullkin",
    "name": "pullkin",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "fcm gcm push notification receive firebase google",
    "author": "WhiteApfel",
    "author_email": "white@pfel.ru",
    "download_url": "https://files.pythonhosted.org/packages/df/b8/76ecdffcaf823389496cc36bd5c23ef93de2c509498b69a4158a8bca6666/pullkin-0.14.0.tar.gz",
    "platform": null,
    "description": "# Pullkin\n\n[![CodeFactor](https://www.codefactor.io/repository/github/whiteapfel/pullkin/badge/master)](https://www.codefactor.io/repository/github/whiteapfel/pullkin/overview/master)\n[![Build Status](https://app.travis-ci.com/WhiteApfel/Pullkin.svg?branch=master)](https://app.travis-ci.com/WhiteApfel/Pullkin)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pullkin)\n![GitHub](https://img.shields.io/github/license/whiteapfel/pullkin)\n![GitHub last commit](https://img.shields.io/github/last-commit/whiteapfel/pullkin)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pullkin)\n\nLike Pushkin, but subscribe to FCM (GCM) and receive notifications\n\nMy alternative implementation \nof [python implementation](https://github.com/Francesco149/push_receiver) \nof [JS implementation](https://github.com/MatthieuLemoine/push-receiver)\n\nTested on python (3.6, 3.8, 3.10, pypy3.7-7.3.5)\n\nI almost didn't write anything to consider it my intellectual property, \njust wrapped the code already written by Franc[e]sco in a design convenient for my own use \n\nNote that for the listening part Franc[e]sco has to pull in http-ece which depends\non a full-blown native crypto library rather than just oscrypto. it is\nan optional dependency, so you'll have to install it explicitly by depending\non `pullkin[listen]`\n\n## Differences\n\n* Add async listener\n* Add async listener-coroutine\n* Replace functions with class of listener\n\n## Usage\n\n### Installation\n\n```shell\npip install pullkin\n```\n\n### How to use\n\n```python\nimport json\nimport os.path\nimport asyncio\n\nfrom pullkin import Pullkin\nfrom pullkin.models import Message, AppCredentials\nfrom pullkin.proto.mcs_proto import DataMessageStanza\n\nSENDER_ID = '<<SENDER_ID>>'  # '1234567890'\n# ANOTHER_SENDER_ID = '<<SENDER_ID>>'  # '1234567890'\nAPP_ID = '<<APP_ID>>'  # '1:1234567890:android:abcdef1234567890'\nAPI_ID = '<<API_ID>>'  # 'AIzaSyDce4zFw4CqLqW2eCOqTbXfDx9a8mRnLpI'\nFIREBASE_NAME = '<<FIREBASE_NAME'  # 'pullkin-example'\nAPP_NAME = '<<APP_NAME>>'  # 'cc.pullkin.example'\n\n#\nANDROID_CERT = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'  \n# 'da39a3ee5e6b4b0d3255bfef95601890afd80709' is default hash\n\npullkin = Pullkin()\n\nif not os.path.exists('.persistent_ids.txt'):\n    with open('.persistent_ids.txt', 'w+') as f:\n        ...\n\nwith open(\".persistent_ids.txt\", \"r\") as f:\n    received_persistent_ids = [x.strip() for x in f]\n\n\n@pullkin.on_notification()\nasync def on_notification(message: Message, data_message: DataMessageStanza):\n    idstr = data_message.persistent_id + \"\\n\"\n    with open(\".persistent_ids.txt\", \"r\") as f:\n        if idstr in f:\n            return\n    with open(\".persistent_ids.txt\", \"a\") as f:\n        f.write(idstr)\n    print(message.notification)\n\n\nasync def main():\n    if not os.path.exists('.pullkin_app_credentials'):\n        with open('.pullkin_app_credentials', 'w+') as f:\n            credentials = await pullkin.register(SENDER_ID, APP_ID, API_ID, FIREBASE_NAME, ANDROID_CERT,  APP_NAME)\n            f.write(json.dumps(credentials.model_dump(mode=\"json\")))\n    else:\n        with open('.pullkin_app_credentials', 'r') as f:\n            credentials = AppCredentials.model_validate(json.loads(f.read()))\n    \n    await pullkin.add_app(sender_id=SENDER_ID, credentials=credentials, persistent_ids=received_persistent_ids)\n    # await pullkin.add_app(sender_id=ANOTHER_SENDER_ID, credentials=another_credentials, persistent_ids=another_received_persistent_ids)\n    \n    \n    await pullkin.run()\n\n\nasyncio.run(main())\n```\n",
    "bugtrack_url": null,
    "license": "Mozilla Public License 2.0",
    "summary": "Subscribe to GCM/FCM and receive notifications like an android app",
    "version": "0.14.0",
    "project_urls": {
        "Homepage": "https://github.com/WhiteApfel/pullkin"
    },
    "split_keywords": [
        "fcm",
        "gcm",
        "push",
        "notification",
        "receive",
        "firebase",
        "google"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4fa5e223f3a6039f21bbf9cacc4341e84b71fba3e9f59050ed0fbaead673993",
                "md5": "61f2390da470463c6c06a397a25e3f6b",
                "sha256": "4959e9bd07338f968336148904a92032a6b81a9ef1a99a067cc5335e9574f214"
            },
            "downloads": -1,
            "filename": "pullkin-0.14.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61f2390da470463c6c06a397a25e3f6b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 29181,
            "upload_time": "2024-02-26T15:50:40",
            "upload_time_iso_8601": "2024-02-26T15:50:40.670644Z",
            "url": "https://files.pythonhosted.org/packages/f4/fa/5e223f3a6039f21bbf9cacc4341e84b71fba3e9f59050ed0fbaead673993/pullkin-0.14.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dfb876ecdffcaf823389496cc36bd5c23ef93de2c509498b69a4158a8bca6666",
                "md5": "157c8d0c4d4a0b72d7b520f6acedcf1a",
                "sha256": "e7ea69f24936ef760ecff2bf9151710d5fda0c41ce944eb4cd793bb98f47deb6"
            },
            "downloads": -1,
            "filename": "pullkin-0.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "157c8d0c4d4a0b72d7b520f6acedcf1a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 25182,
            "upload_time": "2024-02-26T15:50:42",
            "upload_time_iso_8601": "2024-02-26T15:50:42.477148Z",
            "url": "https://files.pythonhosted.org/packages/df/b8/76ecdffcaf823389496cc36bd5c23ef93de2c509498b69a4158a8bca6666/pullkin-0.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 15:50:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "WhiteApfel",
    "github_project": "pullkin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pullkin"
}
        
Elapsed time: 3.12482s