fix some error

This commit is contained in:
pengtao 2019-07-15 16:05:57 +08:00
parent 3a2f80a306
commit e4590830f0

View File

@ -6,8 +6,6 @@ import hashlib
import urllib.request
import tornado.ioloop
import tornado.web
import tornado.ioloop
import tornado.web
import json
from myredis.myredis import my_redis
import datetime
@ -24,30 +22,6 @@ BEGIN = '1999-01-01'
END = '3000-01-01'
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}"
ids = my_redis.hmgetall(key)
info = []
for id in ids:
temp = my_redis.hgetall[f"{id}::info"]
info.append(temp)
return info
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")
all = []
@ -81,7 +55,6 @@ def send_cache_data():
except Exception:
log.error("split data failed", exc_info=True)
# 检查ID是否存在播放列表中以及播放次数是否完毕
pdb.set_trace()
if all:
for line in all:
key = f"{line.get('gameid', 0)}::{line.get('locationid', 0)}"
@ -98,23 +71,48 @@ def send_cache_data():
if not my_redis.exists(f"{line['id']}::info"):
my_redis.hmset(f"{line['id']}::info", line)
len_all = len(all)
log.info(f"write {len_all} to cache!")
class SelfCheckingHandler(tornado.web.RequestHandler):
class DispatchHandler(tornado.web.RequestHandler):
def get(self):
if self.get('c') == 'Ops' and self.get('a') == 'selfChecking':
self._selfCheckingHandler()
elif self.get('c') == 'Ops' and self.get('a') == 'getAdList':
def _selfCheckingHandler(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),
def _selfGetAdList(self):
input = json.loads(self.request.body)
gameid = input['gameid']
localid = input['localtionid']
key = f"{gameid}::{localid}"
ids = my_redis.hmgetall(key)
info = []
for id in ids:
temp = my_redis.hgetall[f"{id}::info"]
info.append(temp)
self.write(json.dumps(info))
])
def make_app():
return tornado.web.Application([(r"/webapp/index[\.]php", DispatchHandler)])
if __name__ == "__main__":
import pdb
send_cache_data() # 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()
send_cache_data()
print('start!')
app = make_app()
app.listen('5555')
tornado.ioloop.PeriodicCallback(send_cache_data, 60000).start()
# tornado.ioloop.IOLoop.current().call_at(time.time() + 60, lambda: sendNotify(conf, conf['sendtime1']))
tornado.ioloop.IOLoop.current().start()