From 9373dce0dfd31c0de9a7b8d429a6e1ea1cab8552 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 27 Nov 2019 11:45:46 -0800 Subject: [PATCH] fix fcm_msg.py test script (force to take devid) Works! --- xwords4/relay/scripts/fcm_msg.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/xwords4/relay/scripts/fcm_msg.py b/xwords4/relay/scripts/fcm_msg.py index 7021be870..0cea7c6bd 100755 --- a/xwords4/relay/scripts/fcm_msg.py +++ b/xwords4/relay/scripts/fcm_msg.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import sys, psycopg2, json, urllib, urllib2 +import argparse, json, psycopg2, sys, urllib, urllib2 from oauth2client.service_account import ServiceAccountCredentials # I'm not checking my key in... @@ -53,19 +53,16 @@ def sendMsg( devid, msg ): break def main(): - to = None - msg = sys.argv[1] - if msg == '--to': - to = sys.argv[2] - msg = sys.argv[3] - elif 2 < len(sys.argv): - usage() - if not to in mykey2.devids.keys(): - print 'Unknown --to param;', to, 'not in', ','.join(mykey2.devids.keys()) - usage() - if not to: usage() - devid = mykey2.devids[to] - print 'sending: "%s" to' % msg, to + parser = argparse.ArgumentParser() + parser.add_argument("msg") + parser.add_argument('--dest-devid', dest = 'DEVID', type = str, required = True, + help = 'fcm devid of target device') + + args = parser.parse_args() + devid = args.DEVID + msg = args.msg + + print 'sending: "%s" to' % msg, devid sendMsg( devid, msg ) ##############################################################################