kefu_robot.py ok
This commit is contained in:
parent
616cade040
commit
0b8e67ddd9
@ -1,11 +1,38 @@
|
|||||||
#coding utf8
|
#coding utf8
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
import hashlib
|
||||||
|
import urllib.request
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
||||||
|
def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'):
|
||||||
|
params_str = ''
|
||||||
|
for key in sorted(params.keys()):
|
||||||
|
params_str = params_str + key + '=' + str(params[key]) + connstr
|
||||||
|
if params_str != '' and connstr != '':
|
||||||
|
params_str = params_str[0:-1]
|
||||||
|
m = hashlib.md5()
|
||||||
|
m.update(params_str)
|
||||||
|
return m.hexdigest() + secret_connstr + str(timestamp) + secret
|
||||||
|
|
||||||
|
def getDaySeconds(time_val, incdays):
|
||||||
|
time_zone = 8
|
||||||
|
return int((time_val + time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * time_zone;
|
||||||
|
|
||||||
|
def sendNotify(conf, sendtime):
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(conf['notify_url'])
|
||||||
|
data = urllib.request.urlopen(req).readall()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
#进入下一次循环
|
||||||
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 0) + sendtime,
|
||||||
|
lambda : sendNotify(conf, sendtime))
|
||||||
|
|
||||||
class SelfCheckingHandler(tornado.web.RequestHandler):
|
class SelfCheckingHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
@ -22,8 +49,12 @@ def make_app():
|
|||||||
])
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
conf = json.loads(open('config/kefu_redissave.json', 'r').read())
|
conf = json.loads(open('config/kefu_robot.json', 'r').read())
|
||||||
|
|
||||||
app = make_app()
|
app = make_app()
|
||||||
app.listen(conf['listen_port'])
|
app.listen(conf['listen_port'])
|
||||||
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 0) + conf['sendtime1'],
|
||||||
|
lambda : sendNotify(conf, conf['sendtime1']))
|
||||||
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 0) + conf['sendtime2'],
|
||||||
|
lambda : sendNotify(conf, conf['sendtime2']))
|
||||||
tornado.ioloop.IOLoop.current().start()
|
tornado.ioloop.IOLoop.current().start()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user