Skip to content
/ pyc2dm Public
forked from appfirst/pyc2dm

Python C2DM client for pushing notifications to Android phones

License

Notifications You must be signed in to change notification settings

shanem/pyc2dm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

Download the code and run python setup.py install

Usage

Basic usage from pyc2dm import C2DM

c = C2DM(email="YOUR USERNAME", password="YOUR PASSWORD", source="COMPANY.APP.VERSION")
c.send_message("REGISTRATION_ID", "COLLAPSE KEY", {"optional":"data", "whatever": "you want"})

This can raise a number of exceptions, some are handled automatically by retrying with exponential backoff. Others, you'll need to handle. Here's a more complete example. You can see all the details by looking through the code. from pyc2dm import * ## Setup logging ##

c = C2DM(email="YOUR USERNAME", password="YOUR PASSWORD", source="COMPANY.APP.VERSION")
try:
    token = c.get_client_token()
except C2DMException as e:
    raise # couldn't get a client token

cache_token_for_future_use(token)
# Then in the future use C2DM(client_token="YOUR TOKEN", source="COMPANY.APP.VERSION")

try:
    c.send_notification("REGISTRATION_ID", "COLLAPSE KEY", {"optional":"data"})
except C2DMInvalidDeviceException as e:
    remove_device("REGISTRATION_ID") ## Remove this device from your list
except C2DMException as e:
    logger.error("Something else bad happened: %s", e)

Testing

To run tests, put your gmail account/password and a valid device registration id into the test.py file, then run python test/test.py

About

Python C2DM client for pushing notifications to Android phones

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%