# -*- coding: utf-8 -*- import os import json import time import hashlib import urllib.request import tornado.ioloop import tornado.web import tornado.ioloop import tornado.web import json from myredis import myredis import datetime class Adlist(tornado.web.RequestHandler): def post(self): res = adlist_workflow(json.loads(self.request.body)) self.write(json.dumps(res)) def adlist_workflow(input): gameid = input['gameid'] localid = input['localtionid'] key = f"{gameid}::{localid}" result = myredis.hmgetall(key) return result def getDaySeconds(time_val, incdays): time_zone = 8 return int((time_val + time_zone * 3600) / 3600 / 24 + incdays) * 3600 * 24 - 3600 * time_zone; def send_cache_data(): now = datetime.datetime.today().strftime("%Y-%m-%d") get_data_sql = "select " def sendNotify(conf, sendtime): try: print('sendNotify start') params = {'key': 'kingsome'} secret = 'fc38349c5d084e920925e614c420be9f' timestamp = time.time() md5signstr = md5Sign(params, secret, timestamp) url = conf['notify_url'] + '×tamp=' + str(timestamp) + '&sign=' + md5signstr req = urllib.request.Request(url) data = urllib.request.urlopen(req).read() print('sendNotify end') except Exception as e: print('sendNotifu error: ' + str(e)) # 进入下一次循环 tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime, lambda: sendNotify(conf, sendtime)) class SelfCheckingHandler(tornado.web.RequestHandler): def get(self): self.write(json.dumps({ 'errcode': 0, 'errmsg': '', 'healthy': 1, 'max_rundelay': 10 }, separators=(',', ':'))) def make_app(): return tornado.web.Application([(r"/webapp/index[\.]php", SelfCheckingHandler), (r"/", hello), ]) if __name__ == "__main__": print('start!') conf = json.loads(open('../config/kefu_robot.json', 'r').read()) app = make_app() app.listen(conf['listen_port']) tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime1'], lambda: sendNotify(conf, conf['sendtime1'])) tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime2'], lambda: sendNotify(conf, conf['sendtime2'])) tornado.ioloop.IOLoop.current().start()