Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 68 lines (44 sloc) 1.72 KB
#!/usr/bin/env python
from apns import APNs, Payload
import optparse
import time
from tornado import ioloop
parser = optparse.OptionParser()
parser.add_option("-c", "--certificate-file",
dest="certificate_file",
help="Path to .pem certificate file")
parser.add_option("-k", "--key-file",
dest="key_file",
help="Path to .pem key file")
parser.add_option("-p", "--push-token",
dest="push_token",
help="Push token")
parser.add_option("-m", "--message",
dest="message",
help="Message")
options, args = parser.parse_args()
if options.certificate_file is None:
parser.error('Must provide --certificate-file')
if options.key_file is None:
parser.error('Must provide --key-file')
if options.push_token is None:
parser.error('Must provide --push-token')
if options.message is None:
parser.error('Must provide --message')
apns = APNs(cert_file=options.certificate_file, key_file=options.key_file,
use_sandbox=True)
def success():
print("Sent push message to APNS gateway.")
ioloop.IOLoop.instance().stop()
def send():
apns.gateway_server.send_notification(0, time.time()+5, options.push_token,
payload, success)
def on_response(status, seq):
print "sent push message to APNS gateway error status %s seq %s" % (status, seq)
def on_connected():
apns.gateway_server.receive_response(on_response)
# Send a notification
payload = Payload(alert=options.message, sound="default", badge=1)
apns.gateway_server.connect(on_connected)
ioloop.IOLoop.instance().add_timeout(time.time()+5, send)
ioloop.IOLoop.instance().start()
Something went wrong with that request. Please try again.