fix some error
This commit is contained in:
parent
c43cd11065
commit
b92c3f1414
83
ad_interface_tornado.py
Normal file
83
ad_interface_tornado.py
Normal file
@ -0,0 +1,83 @@
|
||||
# -*- 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()
|
30
add_task_1min.py
Normal file
30
add_task_1min.py
Normal file
@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding:utf-8 -*-
|
||||
from tornado import web, ioloop
|
||||
import datetime
|
||||
import time
|
||||
|
||||
class MainHandler(web.RequestHandler):
|
||||
def get(self):
|
||||
self.write('Hello Kingsome, I am alive!')
|
||||
|
||||
|
||||
def add_task():
|
||||
# print '2s ', datetime.datetime.now()
|
||||
time.sleep(2)
|
||||
print(
|
||||
"执行f2s")
|
||||
|
||||
|
||||
def remove_task():
|
||||
# print '5s ', datetime.datetime.now()
|
||||
print(
|
||||
"执行f5s")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
application = web.Application([(r'/', MainHandler), ])
|
||||
application.listen(8081)
|
||||
ioloop.PeriodicCallback(add_task, 2000).start() # start scheduler 每隔2s执行一次f2s
|
||||
ioloop.PeriodicCallback(remove_task, 5000).start() # start scheduler 每隔5s执行一次f5s
|
||||
ioloop.IOLoop.instance().start()
|
Loading…
x
Reference in New Issue
Block a user