mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
some changes accumulated as script was running
This commit is contained in:
parent
4dddd2da42
commit
618d8530f2
1 changed files with 22 additions and 7 deletions
|
@ -1,10 +1,13 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys, gcm, psycopg2
|
||||
import sys, gcm, psycopg2, json
|
||||
|
||||
# I'm not checking my key in...
|
||||
import mykey
|
||||
|
||||
def usage():
|
||||
print 'usage:', sys.argv[0], '[--to <name>] msg'
|
||||
sys.exit()
|
||||
|
||||
def msgViaGCM( devid, msg ):
|
||||
instance = gcm.GCM( mykey.myKey )
|
||||
|
@ -14,18 +17,30 @@ def msgViaGCM( devid, msg ):
|
|||
|
||||
response = instance.json_request( registration_ids = [devid],
|
||||
data = data )
|
||||
|
||||
if 'errors' in response:
|
||||
for error, reg_ids in response.items():
|
||||
print error
|
||||
response = response['errors']
|
||||
if 'NotRegistered' in response:
|
||||
ids = response['NotRegistered']
|
||||
for id in ids:
|
||||
print 'need to remove "', id, '" from db'
|
||||
else:
|
||||
print 'no errors'
|
||||
|
||||
|
||||
def main():
|
||||
to = None
|
||||
msg = sys.argv[1]
|
||||
print 'got "%s"' % msg
|
||||
msgViaGCM( mykey.myBlaze, msg )
|
||||
if msg == '--to':
|
||||
to = sys.argv[2]
|
||||
msg = sys.argv[3]
|
||||
elif 2 < len(sys.argv):
|
||||
usage()
|
||||
if not to in mykey.devids.keys():
|
||||
print 'Unknown --to param;', to, 'not in', ','.join(mykey.devids.keys())
|
||||
usage()
|
||||
if not to: usage()
|
||||
devid = mykey.devids[to]
|
||||
print 'sending: "%s" to' % msg, to
|
||||
msgViaGCM( devid, msg )
|
||||
|
||||
##############################################################################
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue