From 2df4199a77a56f1a6e9c99e5522c812c2750a7c0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 8 Nov 2012 06:13:01 -0800 Subject: [PATCH] test script for messaging devices --- xwords4/relay/scripts/.gitignore | 3 +++ xwords4/relay/scripts/gcm_msg.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 xwords4/relay/scripts/.gitignore create mode 100755 xwords4/relay/scripts/gcm_msg.py diff --git a/xwords4/relay/scripts/.gitignore b/xwords4/relay/scripts/.gitignore new file mode 100644 index 000000000..528f569c1 --- /dev/null +++ b/xwords4/relay/scripts/.gitignore @@ -0,0 +1,3 @@ +gcm.py +gcm.pyc +mykey.py* diff --git a/xwords4/relay/scripts/gcm_msg.py b/xwords4/relay/scripts/gcm_msg.py new file mode 100755 index 000000000..d90e4137a --- /dev/null +++ b/xwords4/relay/scripts/gcm_msg.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +import sys, gcm, psycopg2 + +# I'm not checking my key in... +import mykey + + +def msgViaGCM( devid, msg ): + instance = gcm.GCM( mykey.myKey ) + data = { 'title' : 'Msg from Darth', + 'msg' : msg, + } + + response = instance.json_request( registration_ids = [devid], + data = data ) + + if 'errors' in response: + for error, reg_ids in response.items(): + print error + else: + print 'no errors' + + +def main(): + msg = sys.argv[1] + print 'got "%s"' % msg + msgViaGCM( mykey.myBlaze, msg ) + +############################################################################## +if __name__ == '__main__': + main()