mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
unregister (flag in db) devids google says are unregistered
This commit is contained in:
parent
2859ec9132
commit
e920fbcaff
1 changed files with 11 additions and 9 deletions
|
@ -55,13 +55,19 @@ def init():
|
||||||
def getPendingMsgs( con, typ ):
|
def getPendingMsgs( con, typ ):
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
query = """SELECT id, devid FROM msgs
|
query = """SELECT id, devid FROM msgs
|
||||||
WHERE devid IN (SELECT id FROM devices WHERE devtype=%d)
|
WHERE devid IN (SELECT id FROM devices WHERE devtype=%d and NOT unreg)
|
||||||
AND NOT connname IN (SELECT connname FROM games WHERE dead); """
|
AND NOT connname IN (SELECT connname FROM games WHERE dead); """
|
||||||
cur.execute(query % typ)
|
cur.execute(query % typ)
|
||||||
result = cur.fetchall()
|
result = cur.fetchall()
|
||||||
if g_debug: print "getPendingMsgs=>", result
|
if g_debug: print "getPendingMsgs=>", result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def unregister( gcmid ):
|
||||||
|
global g_con
|
||||||
|
print "unregister(", gcmid, ")"
|
||||||
|
query = "UPDATE devices SET unreg=TRUE WHERE id = '%s'" % gcmid
|
||||||
|
g_con.cursor().execute( query )
|
||||||
|
|
||||||
def asGCMIds(con, devids, typ):
|
def asGCMIds(con, devids, typ):
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
query = "SELECT devid FROM devices WHERE devtype = %d AND id IN (%s)" \
|
query = "SELECT devid FROM devices WHERE devtype = %d AND id IN (%s)" \
|
||||||
|
@ -72,20 +78,15 @@ def asGCMIds(con, devids, typ):
|
||||||
def notifyGCM( devids, typ ):
|
def notifyGCM( devids, typ ):
|
||||||
if typ == DEVTYPE_GCM:
|
if typ == DEVTYPE_GCM:
|
||||||
instance = gcm.GCM( mykey.myKey )
|
instance = gcm.GCM( mykey.myKey )
|
||||||
data = { 'getMoves': True,
|
data = { 'getMoves': True, }
|
||||||
# 'title' : 'Msg from Darth',
|
|
||||||
# 'msg' : "I am your father, Luke.",
|
|
||||||
}
|
|
||||||
response = instance.json_request( registration_ids = devids,
|
response = instance.json_request( registration_ids = devids,
|
||||||
# restricted_package_name = 'org.eehouse.android.xw4',
|
|
||||||
data = data,
|
data = data,
|
||||||
# collapse_key = 'NewMove',
|
|
||||||
)
|
)
|
||||||
if 'errors' in response:
|
if 'errors' in response:
|
||||||
response = response['errors']
|
response = response['errors']
|
||||||
if 'NotRegistered' in response:
|
if 'NotRegistered' in response:
|
||||||
for id in response['NotRegistered']:
|
for gcmid in response['NotRegistered']:
|
||||||
print 'need to remove "', id, '" from db'
|
unregister( gcmid )
|
||||||
else:
|
else:
|
||||||
print "got some kind of error"
|
print "got some kind of error"
|
||||||
else:
|
else:
|
||||||
|
@ -184,6 +185,7 @@ def main():
|
||||||
print "devices needing notification:", targets
|
print "devices needing notification:", targets
|
||||||
notifyGCM( asGCMIds( g_con, targets, typ ), typ )
|
notifyGCM( asGCMIds( g_con, targets, typ ), typ )
|
||||||
pruneSent( devids )
|
pruneSent( devids )
|
||||||
|
elif g_debug: print "no targets after backoff"
|
||||||
else:
|
else:
|
||||||
emptyCount += 1
|
emptyCount += 1
|
||||||
if (0 == (emptyCount%5)) and not g_debug:
|
if (0 == (emptyCount%5)) and not g_debug:
|
||||||
|
|
Loading…
Reference in a new issue