def response_ding_action(sid, cid, push_token): db = DB() sql = "select com,nu from t_dd_kuaidi where cid='%s'" % cid data = db.query(sql) com = data[0][0] nu = data[0][1] dtype = "ding" q.enqueue(query_kuaidi_info, sid, cid, com, nu, dtype, push_token)
def loop_kuaidi_task(sid): db = DB() sql = """ select cid, com, nu from t_dd_kuaidi where active=1 """ print "Start loop kaudi task..." data = db.query(sql) dtype = 'loop' for record in data: cid, com, nu = record[0], record[1], record[2] q.enqueue(query_kuaidi_info, sid, cid, com, nu, dtype)
def push_handler(sid, cid, ck_time, last_time, context, dtype, push_token): db = DB() sql = "select state_time, check_time from t_dd_kuaidi where cid='%s'" % cid data = db.query(sql) state_time = data[0][0] check_time = data[0][1] # update check_time udb = DB() sql = "update t_dd_kuaidi set check_time='%s' where cid='%s'" % (ck_time, cid) print "Update check_time,sql:", sql udb.update(sql) #print "state_time:%s, last_time:%s" % (state_time, last_time) if state_time != last_time or dtype=='ding': # push new state and update push_time, state_time print "Start push message..." Push = PushService(sid, cid, push_token) status_code = Push.push_text('快递提醒', context) now = int(time.time()) push_time = datetime.fromtimestamp(now) if status_code == 200: print "Push message Successful!" sdb = DB() sql = "update t_dd_kuaidi set state_time='%s',\ push_time='%s' where cid='%s'" % (last_time, push_time, cid) sdb.update(sql) print "Update state_time, push_time:%s" % sql else: print "Push message Error!" print "Status code: %s, Error accurs when push new state: cid=%s, ck_time=%s,\ last_time=%s, context=%s, push_token=%s, push_time=%s\ " % (status_code, cid, ck_time, last_time, context, push_token, push_time)