tornado_api.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. from wechat_action.sql_models import DB
  2. from settings import using_config
  3. import tornado.log
  4. import tornado.ioloop
  5. import tornado.web
  6. from logging import handlers
  7. from wechat_action.login_ad import LogIn
  8. from wechat_action import sql_tools
  9. import threading
  10. from web_module import user_action
  11. from sqlalchemy import Table
  12. import json
  13. import pickle
  14. from datetime import datetime
  15. # TODO:需要添加上supervisor,来维护进程
  16. # TODO:有时间需要对tornado进行改进
  17. # TODO:需要有一套上线工具,来维持线上稳定
  18. db = DB(config=using_config)
  19. wechat_cookies_table = Table('wechat_cookies', db.metadata,
  20. autoload=True, autoload_with=db.engine)
  21. layout_typesetting_table = Table('layout_typesetting', db.metadata,
  22. autoload=True, autoload_with=db.engine)
  23. ad_plan_typesetting_table = Table('ad_plan_typesetting', db.metadata,
  24. autoload=True, autoload_with=db.engine)
  25. action_record_table = Table('action_record', db.metadata,
  26. autoload=True, autoload_with=db.engine)
  27. layout_create_action = 'create_ad_layout'
  28. ad_plan_create_action = 'create_ad_plan'
  29. refresh_wechat_action = 'refresh_wechat_info'
  30. # 1.实现本机服务
  31. # 2.实现线上docker-selenium服务
  32. class BaseHandler(tornado.web.RequestHandler):
  33. def options(self):
  34. pass
  35. def set_default_headers(self):
  36. self.set_header('Access-Control-Allow-Origin', '*')
  37. self.set_header('Access-Control-Allow-Headers', '*')
  38. self.set_header('Access-Control-Max-Age', 1000)
  39. self.set_header('Content-type', '*')
  40. self.set_header('Access-Control-Allow-Methods', '*')
  41. class create_ad_plan_local(BaseHandler):
  42. def post(self):
  43. request_dict = json.loads(self.request.body, encoding='utf-8')
  44. user_id = request_dict['user_id']
  45. ad_plan_list = request_dict['plan_list']
  46. sql_session = db.DBSession()
  47. if user_id is None or ad_plan_list is None:
  48. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  49. return
  50. # 落地页名字精确到毫秒,默认是全局唯一
  51. for _ in ad_plan_list:
  52. ad_plan_name = _['title']
  53. ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name,
  54. 'typesetting': json.dumps(_, ensure_ascii=False)}
  55. ad_plan_typesetting_inserte = sql_tools.save_ad_plan_typesetting_info(
  56. ad_plan_typesetting_info=ad_plan_typesetting_info,
  57. table_ad_plan_typesetting=ad_plan_typesetting_table)
  58. sql_session.execute(ad_plan_typesetting_inserte)
  59. sql_session.commit()
  60. self.write({'status': {'msg': 'success', "RetCode": 200}})
  61. class create_ad_plan(BaseHandler):
  62. # TODO:只要tornado开着就不允许修改数据库,------想好之后上线如何操作
  63. # TODO:名字检查----只保留三种符号(.-_),中文字符长度一,数字字符长度二
  64. @staticmethod
  65. def check_task(user_id):
  66. # TODO:检查是否同user_id的任务在跑中,有的话只保存任务.不做其他事情
  67. sql_session = db.DBSession()
  68. result = sql_tools.get_task_in_hand_num(user_id, sql_session)
  69. return result
  70. def save_task_info(self, user_id, ad_plan_list, sql_session, task_name):
  71. # 2.数据存入数据库
  72. if user_id is None or ad_plan_list is None:
  73. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  74. return
  75. # 2.1存计划数据
  76. for _ in ad_plan_list:
  77. ad_plan_name = _['title']
  78. ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name,
  79. 'typesetting': json.dumps(_, ensure_ascii=False)}
  80. ad_plan_typesetting_inserte = sql_tools.save_ad_plan_typesetting_info(
  81. ad_plan_typesetting_info=ad_plan_typesetting_info,
  82. table_ad_plan_typesetting=ad_plan_typesetting_table)
  83. sql_session.execute(ad_plan_typesetting_inserte)
  84. sql_session.commit()
  85. for _ in ad_plan_list:
  86. for action_type in [layout_create_action, ad_plan_create_action]:
  87. object_name = _['title'] if action_type == ad_plan_create_action else \
  88. _['idea']['jump_type_page_type'][
  89. 'layout_name']
  90. action_info = {'user_id': user_id, 'service_name': _['service_name'],
  91. 'wechat_name': _['wechat_name'],
  92. 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
  93. 'status': 'todo'}
  94. record_insert = sql_tools.save_action_record(action_record_info=action_info,
  95. table_action_record=action_record_table)
  96. sql_session.execute(record_insert)
  97. sql_session.commit()
  98. def post(self):
  99. sql_session = db.DBSession()
  100. log_ad = None
  101. try:
  102. request_dict = json.loads(self.request.body, encoding='utf-8')
  103. ad_plan_list = request_dict['plan_list']
  104. user_id = request_dict['user_id']
  105. # 2.2存行为记录
  106. task_name = 'user_id: {user_id} time:{time_sign} action:create_plan'.format(user_id=user_id,
  107. time_sign=datetime.now().strftime(
  108. "%Y-%m-%d, %H:%M:%S"))
  109. # 4.开始运行
  110. if not self.check_task(user_id=user_id):
  111. # 1.查看是否cookie可用
  112. log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
  113. self.save_task_info(user_id, ad_plan_list, sql_session, task_name)
  114. threading.Thread(target=user_action.carry_plan,
  115. args=(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name)).start()
  116. else:
  117. self.save_task_info(user_id, ad_plan_list, sql_session, task_name)
  118. except Exception as e:
  119. if log_ad:
  120. log_ad.driver.quit()
  121. logging.error(str(e))
  122. self.write('eror')
  123. raise
  124. finally:
  125. sql_session.commit()
  126. class get_ad_plan_local(BaseHandler):
  127. def get(self):
  128. user_id = self.get_argument('user_id', None)
  129. layout_name = self.get_argument('plan_name', None)
  130. sql_session = db.DBSession()
  131. if user_id is None:
  132. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  133. return
  134. # 落地页名字精确到毫秒,默认是全局唯一
  135. if layout_name:
  136. result = sql_tools.get_plan_typesetting_rough(sql_session=sql_session, user_id=user_id,
  137. typesetting_name=layout_name)
  138. else:
  139. # TODO:之后修改一下,让其查询效率高点,like效率过低
  140. layout_name = ''
  141. result = sql_tools.get_plan_typesetting_rough(sql_session=sql_session, user_id=user_id,
  142. typesetting_name=layout_name)
  143. result_ = []
  144. for i in range(len(result)):
  145. typesetting, name, create_time, update_time = result[i]
  146. _ = {}
  147. _['typesetting'] = json.loads(typesetting)
  148. _['ad_plan_name'] = name
  149. _['id'] = i
  150. _['create_time'] = create_time.strftime("%Y-%m-%d %H:%M:%S")
  151. _['update_time'] = update_time.strftime("%Y-%m-%d %H:%M:%S")
  152. result_.append(_)
  153. self.write({'status': {'msg': 'success', "RetCode": 200},
  154. 'local_ad_plan_info': result_})
  155. class create_ad_layout_local(BaseHandler):
  156. def post(self):
  157. # TODO:返回一个layout_name重复的一个信息
  158. request_dict = json.loads(self.request.body)
  159. user_id = request_dict['user_id']
  160. layout_typesetting = request_dict['layout_typesetting']
  161. layout_name = request_dict['layout_name']
  162. sql_session = db.DBSession()
  163. if user_id is None or layout_name is None or layout_typesetting is None:
  164. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  165. return
  166. # 落地页名字精确到毫秒,默认是全局唯一
  167. layout_typesetting_info = {'user_id': user_id, 'name': layout_name,
  168. 'typesetting': layout_typesetting}
  169. layout_typesetting_inserte = sql_tools.save_layout_typesetting_info(
  170. layout_typesetting_info=layout_typesetting_info,
  171. table_layout_typesetting=layout_typesetting_table)
  172. sql_session.execute(layout_typesetting_inserte)
  173. sql_session.commit()
  174. self.write({'status': {'msg': 'success', "RetCode": 200}})
  175. class get_ad_layout_local(BaseHandler):
  176. def get(self):
  177. user_id = self.get_argument('user_id', None)
  178. layout_name = self.get_argument('layout_name', None)
  179. sql_session = db.DBSession()
  180. if user_id is None:
  181. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  182. return
  183. # 落地页名字精确到毫秒,默认是全局唯一
  184. if layout_name:
  185. result = sql_tools.get_layout_typesetting_rough(sql_session=sql_session, user_id=user_id,
  186. typesetting_name=layout_name)
  187. else:
  188. # TODO:之后修改一下,让其查询效率高点,like效率过低
  189. layout_name = ''
  190. result = sql_tools.get_layout_typesetting_rough(sql_session=sql_session, user_id=user_id,
  191. typesetting_name=layout_name)
  192. result_ = []
  193. for i in range(len(result)):
  194. typesetting, name, create_time, update_time = result[i]
  195. _ = {}
  196. _['typesetting'] = json.loads(typesetting)
  197. _['layout_name'] = name
  198. _['id'] = i
  199. _['create_time'] = create_time.strftime("%Y-%m-%d %H:%M:%S")
  200. _['update_time'] = update_time.strftime("%Y-%m-%d %H:%M:%S")
  201. result_.append(_)
  202. self.write({'status': {'msg': 'success', "RetCode": 200},
  203. 'local_layout_info': result_})
  204. # TODO:wechat_info,human_info 这两张表有空时需要进行对应改进
  205. # TODO:ad_human_info ,ad_wecaht_info 两个的行为需要与create_ad_plan 进行交互
  206. class ad_human_info(BaseHandler):
  207. # TODO:设置一下update---table,如果失败了sql_session需要关闭
  208. @staticmethod
  209. def refresh_wechat_cookies(tornado_web, user_id):
  210. # TODO:添加互动接口,添加状态字段,打开selenium就变换
  211. # 1.返回二维码链接
  212. # ----1.查看cookie是否可用
  213. sql_session = db.DBSession()
  214. cookie_db = sql_tools.get_wechat_cookies(sql_session, user_id=user_id)
  215. # 进行登录操作
  216. log_ad = LogIn(user_id=user_id)
  217. # 使driver可以使用
  218. cookie_canuse = False
  219. if cookie_db:
  220. cookie_db = pickle.loads(cookie_db)
  221. if not log_ad.wechat_cookies_check_alive(cookie_db):
  222. # cookie 不能使用
  223. wechat_code = log_ad.log_in()
  224. tornado_web.write({'status': {'msg': 'success', "RetCode": 200},
  225. 'wechat_code': wechat_code})
  226. logging.info('cookie can not use')
  227. else:
  228. # cookie 可以继续使用
  229. cookie_canuse = True
  230. log_ad.driver.get('https://a.weixin.qq.com/index.html')
  231. tornado_web.write({'status': {'msg': 'success', "RetCode": 200}})
  232. else:
  233. # cookie 不能使用
  234. wechat_code = log_ad.log_in()
  235. tornado_web.write({'status': {'msg': 'success', "RetCode": 200},
  236. 'wechat_code': wechat_code})
  237. return log_ad, cookie_canuse
  238. # 1.人群包获取
  239. def get(self):
  240. sql_session = db.DBSession()
  241. log_ad = None
  242. try:
  243. # 0.是否刷新
  244. # 1.获取userid,以及是否刷新
  245. user_id = self.get_argument("user_id", None)
  246. human_package_name = self.get_argument('human_package_name', None)
  247. is_refresh = self.get_argument("is_refresh", None)
  248. wechat_name = self.get_argument('wechat_name', None)
  249. service_name = self.get_argument('service_name', None)
  250. if user_id is None or is_refresh is None or wechat_name is None or service_name is None:
  251. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  252. return
  253. # TODO:一个涉及到selenium-driver的请求-生命周期.----看一下tornado是怎么处理请求的生命周期
  254. if int(is_refresh) == 1:
  255. if not create_ad_plan.check_task(user_id=user_id):
  256. log_ad, cookie_canuse = self.refresh_wechat_cookies(self, user_id=user_id)
  257. task_name = 'user_id: {user_id} time:{time_sign} action:refresh_wechat_info'.format(
  258. user_id=user_id,
  259. time_sign=datetime.now().strftime(
  260. "%Y-%m-%d, %H:%M:%S"))
  261. # 行为记录
  262. action_type = refresh_wechat_action
  263. object_name = ''
  264. service_name = ''
  265. wechat_name = ''
  266. action_info = {'user_id': user_id, 'service_name': service_name, 'wechat_name': wechat_name,
  267. 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
  268. 'status': 'todo'}
  269. record_insert = sql_tools.save_action_record(action_record_info=action_info,
  270. table_action_record=action_record_table)
  271. sql_session.execute(record_insert)
  272. sql_session.commit()
  273. threading.Thread(target=user_action.get_human_info,
  274. args=(
  275. user_id, log_ad, db, cookie_canuse, task_name)).start()
  276. else:
  277. self.write({'status': {'msg': '', "RetCode": 200}})
  278. else:
  279. # 1.查看是否在刷新,
  280. # 在刷新中,
  281. # 返回正在刷新
  282. # -------不管上面逻辑让他们多刷新几次
  283. # 不在刷新
  284. # 返回对应数据
  285. # 2.获取userid对应数据
  286. result = sql_tools.get_human_info(sql_session=sql_session,
  287. service_name=service_name, wechat_name=wechat_name)
  288. result = json.loads(result)
  289. if human_package_name:
  290. result = [_ for _ in result if human_package_name in _['name']]
  291. result_ = []
  292. for i in range(len(result)):
  293. _ = result[i]
  294. _['id'] = i
  295. result_.append(_)
  296. self.write({'status': {'msg': 'success', "RetCode": 200},
  297. 'human_info': result})
  298. except Exception as e:
  299. if log_ad:
  300. log_ad.driver.quit()
  301. logging.error(str(e))
  302. raise
  303. finally:
  304. sql_session.commit()
  305. class ad_wechat_info(BaseHandler):
  306. # 1.公众号相关信息获取
  307. def get(self):
  308. sql_session = db.DBSession()
  309. log_ad = None
  310. try:
  311. # TODO:添加分页,
  312. # 公众号,服务商,唯一id设计或者获取
  313. # 0.是否刷新
  314. # 1.获取userid,以及是否刷新
  315. user_id = self.get_argument("user_id", None)
  316. is_refresh = self.get_argument("is_refresh", None)
  317. if user_id is None or is_refresh is None:
  318. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  319. return
  320. if int(is_refresh) == 1:
  321. # 检查有无其他任务在处理中,有则等待
  322. if not create_ad_plan.check_task(user_id=user_id):
  323. log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
  324. task_name = 'user_id: {user_id} time:{time_sign} action:refresh_wechat_info'.format(
  325. user_id=user_id,
  326. time_sign=datetime.now().strftime(
  327. "%Y-%m-%d, %H:%M:%S"))
  328. # 行为记录
  329. action_type = refresh_wechat_action
  330. object_name = ''
  331. service_name = ''
  332. wechat_name = ''
  333. action_info = {'user_id': user_id, 'service_name': service_name, 'wechat_name': wechat_name,
  334. 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
  335. 'status': 'todo'}
  336. record_insert = sql_tools.save_action_record(action_record_info=action_info,
  337. table_action_record=action_record_table)
  338. sql_session.execute(record_insert)
  339. sql_session.commit()
  340. threading.Thread(target=user_action.get_human_info,
  341. args=(
  342. user_id, log_ad, db, cookie_canuse, task_name)).start()
  343. else:
  344. self.write({'status': {'msg': '', "RetCode": 200}})
  345. else:
  346. result = sql_tools.get_wechat_info(sql_session=sql_session, user_id=user_id)
  347. result_list = []
  348. for _ in result:
  349. service_name, wechat_name = _
  350. result_list.append({'service_name': service_name, 'wechat_name': wechat_name})
  351. self.write({'status': {'msg': 'success', "RetCode": 200},
  352. 'wechat_info': result_list})
  353. except Exception as e:
  354. if log_ad:
  355. log_ad.driver.quit()
  356. logging.error(str(e))
  357. raise
  358. finally:
  359. sql_session.commit()
  360. class delete_ad_layout(BaseHandler):
  361. def get(self):
  362. user_id = self.get_argument('user_id', None)
  363. layout_name = self.get_argument('layout_name', None)
  364. sql_session = db.DBSession()
  365. if user_id is None or layout_name is None:
  366. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  367. return
  368. # 落地页名字精确到毫秒,默认是全局唯一
  369. sql_tools.delete_layout_typesetting_vir(sql_session=sql_session, user_id=user_id,
  370. typesetting_name=layout_name)
  371. self.write({'status': {'msg': 'success', "RetCode": 200}})
  372. class delete_ad_plan(BaseHandler):
  373. def get(self):
  374. user_id = self.get_argument('user_id', None)
  375. plan_name = self.get_argument('plan_name', None)
  376. service_name = self.get_argument('service_name', None)
  377. wechat_name = self.get_argument('wechat_name', None)
  378. sql_session = db.DBSession()
  379. if user_id is None or plan_name is None:
  380. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  381. return
  382. # 落地页名字精确到毫秒,默认是全局唯一
  383. sql_tools.delete_ad_plan_typesetting_vir(sql_session=sql_session, user_id=user_id,
  384. typesetting_name=plan_name, wechat_name=wechat_name,
  385. service_name=service_name)
  386. self.write({'status': {'msg': 'success', "RetCode": 200}})
  387. class get_ad_wechat_service_name(BaseHandler):
  388. def get(self):
  389. user_id = self.get_argument('user_id', None)
  390. sql_session = db.DBSession()
  391. if user_id is None:
  392. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  393. return
  394. result = sql_tools.get_wechat_info_service_name(sql_session=sql_session, user_id=user_id)
  395. result_list = []
  396. for _ in result:
  397. service_name = _
  398. result_list.append({'service_name': service_name})
  399. self.write({'status': {'msg': 'success', "RetCode": 200},
  400. 'wechat_info': result_list})
  401. class get_ad_wechat_wechat_name(BaseHandler):
  402. def get(self):
  403. user_id = self.get_argument('user_id', None)
  404. service_name = self.get_argument('service_name', None)
  405. sql_session = db.DBSession()
  406. if user_id is None or service_name is None:
  407. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  408. return
  409. result = sql_tools.get_wechat_info_wechat_name(sql_session=sql_session, user_id=user_id,
  410. service_name=service_name)
  411. result_list = []
  412. for _ in result:
  413. service_name, wechat_name = _
  414. result_list.append({'service_name': service_name, 'wechat_name': wechat_name})
  415. self.write({'status': {'msg': 'success', "RetCode": 200},
  416. 'wechat_info': result_list})
  417. class get_plan_action_record(BaseHandler):
  418. def get(self):
  419. user_id = self.get_argument('user_id', None)
  420. service_name = self.get_argument('service_name', None)
  421. wechat_name = self.get_argument('wechat_name', None)
  422. status = self.get_argument('status', None)
  423. plan_name = self.get_argument('plan_name', None)
  424. sql_session = db.DBSession()
  425. if user_id is None:
  426. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  427. return
  428. # 落地页名字精确到毫秒,默认是全局唯一
  429. result = sql_tools.get_plan_record(sql_session=sql_session, user_id=user_id,
  430. service_name=service_name, wechat_name=wechat_name,
  431. status=status, plan_name=plan_name)
  432. result_ = []
  433. for i in range(len(result)):
  434. user_id, name, service_name, wechat_name, create_time, status, typesetting, wechat_id_info = result[i]
  435. _ = {}
  436. _['typesetting'] = json.loads(typesetting)
  437. _['ad_plan_name'] = name
  438. _['id'] = i
  439. _['create_time'] = create_time.strftime("%Y-%m-%d %H:%M:%S")
  440. _['service_name'] = service_name
  441. _['wechat_name'] = wechat_name
  442. _['wechat_id_info'] = wechat_id_info
  443. _['status'] = status
  444. result_.append(_)
  445. self.write({'status': {'msg': 'success', "RetCode": 200},
  446. 'local_ad_plan_info': result_})
  447. class get_all_ad_task(BaseHandler):
  448. def get(self):
  449. user_id = self.get_argument('user_id', None)
  450. sql_session = db.DBSession()
  451. if user_id is None:
  452. self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
  453. return
  454. # 落地页名字精确到毫秒,默认是全局唯一
  455. result = sql_tools.get_ad_task(sql_session=sql_session, user_id=user_id)
  456. task_dict = {}
  457. localtion = ['wechat', '']
  458. for _ in result:
  459. task_name, status, task_status_num, create_time, typesetting = _
  460. typesetting = json.loads(typesetting)
  461. if typesetting['plan_base'][1] == 'pyq':
  462. localtion[1] = 'pyq'
  463. create_time = create_time.strftime("%Y-%m-%d %H:%M:%S")
  464. if task_name not in task_dict.keys():
  465. task_dict[task_name] = {}
  466. task_dict[task_name][status] = (task_status_num, create_time)
  467. result_ = []
  468. num = 0
  469. for k, v in task_dict.items():
  470. # TODO:修改为dict的sort
  471. sum_num = 0
  472. new_dict = {}
  473. create_time = None
  474. for k_, v_ in v.items():
  475. task_status_num, create_time = v_
  476. sum_num = sum_num + task_status_num
  477. new_dict[k_] = task_status_num
  478. status = 'todo' if 'todo' in new_dict.keys() else 'done'
  479. task_dict[k]['sum_num'] = sum_num
  480. new_dict['sum_num'] = sum_num
  481. result_.append(
  482. {'task_name': k, 'task_info': new_dict, 'create_time': create_time, 'channel': localtion[0],
  483. 'localtion': localtion[1], 'id': num, 'status': status})
  484. num = num + 1
  485. self.write({'status': {'msg': 'success', "RetCode": 200},
  486. 'local_ad_plan_info': result_})
  487. def heart_jump():
  488. # TODO:tornado 心跳检测,下周做----线程不断检查,线程生命周期60分钟
  489. pass
  490. def make_app():
  491. return tornado.web.Application([
  492. ("/get_all_ad_task", get_all_ad_task), # 获取所有任务状态,
  493. ("/create_ad_plan", create_ad_plan), #
  494. ("/get_ad_wechat_service_name", get_ad_wechat_service_name),
  495. ("/get_ad_wechat_wechat_name", get_ad_wechat_wechat_name),
  496. # ("/create_ad_plan_local", create_ad_plan_local),
  497. ("/create_ad_layout_local", create_ad_layout_local),
  498. ("/get_layout_local", get_ad_layout_local),
  499. ("/get_ad_plan_local", get_ad_plan_local),
  500. ("/delete_layout_local", delete_ad_layout),
  501. ("/delete_ad_plan_local", delete_ad_plan),
  502. # ("/create_ad_layout_remote", create_ad_layout_remote),
  503. ("/ad_human_info", ad_human_info),
  504. ("/ad_wechat_info", ad_wechat_info),
  505. ("/get_plan_action_record", get_plan_action_record),
  506. ], debug=True, autoreload=True)
  507. if __name__ == "__main__":
  508. import logging
  509. logging.basicConfig(
  510. handlers=[
  511. logging.handlers.RotatingFileHandler('./tornado.log',
  512. maxBytes=10 * 1024 * 1024,
  513. backupCount=5,
  514. encoding='utf-8')
  515. , logging.StreamHandler() # 供输出使用
  516. ],
  517. level=logging.INFO,
  518. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  519. )
  520. handler = logging.FileHandler('tornado.log')
  521. logger = logging.getLogger()
  522. logger.addHandler(handler)
  523. logger.setLevel(logging.INFO)
  524. app = make_app()
  525. app.listen(8888)
  526. tornado.ioloop.IOLoop.current().start()