def active_kuaidi_tixing(cid): try: db = DB() sql = "update t_dd_kuaidi set active=1 where cid = '%s'" % cid db.update(sql) print "Successful to Active cid:%s from t_dd_kuaidi!" % cid except Exception,e: print "Error:Faild active cid:%s from t_dd_kuaidi!" % cid print "Failed info:", e print "sql:",sql
def add_kuaidi_tixing(cid, com, nu): db = DB() now = int(time.time()) create_time = datetime.fromtimestamp(now) try: sql = "insert into t_dd_kuaidi(cid, com, nu, create_time, active)\ values('{0}', '{1}', '{2}', '{3}', 1)".format(cid, com, nu, create_time) db.update(sql) print "Successful to add kuaidi tixing: cid=%s, com=%s,\ nu=%s" % (cid, com, nu) except Exception,e: print "Error: Failed to add kuaidi tixing: cid=%s, com=%s,\ nu=%s" % (cid, com, nu) print "Failed info:", e print "sql:", sql
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)