|
@@ -72,7 +72,6 @@ class create_ad_plan_local(BaseHandler):
|
|
|
|
|
|
class create_ad_plan(BaseHandler):
|
|
|
# TODO:只要tornado开着就不允许修改数据库,------想好之后上线如何操作
|
|
|
- # TODO:需要与刷新用户cookie相关action 联动,---------正在刷新用户信息时,不能进行计划创建.反之同理
|
|
|
|
|
|
# TODO:名字检查----只保留三种符号(.-_),中文字符长度一,数字字符长度二
|
|
|
|
|
@@ -88,52 +87,53 @@ class create_ad_plan(BaseHandler):
|
|
|
sql_session = db.DBSession()
|
|
|
request_dict = json.loads(self.request.body, encoding='utf-8')
|
|
|
print(request_dict)
|
|
|
- user_id = request_dict['user_id']
|
|
|
ad_plan_list = request_dict['plan_list']
|
|
|
+ user_id = request_dict['user_id']
|
|
|
|
|
|
- # 1.查看是否cookie可用
|
|
|
- log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
-
|
|
|
- # 2.数据存入数据库
|
|
|
- print(user_id, ad_plan_list)
|
|
|
- if user_id is None or ad_plan_list is None:
|
|
|
- self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
|
|
|
- return
|
|
|
- # 2.1存计划数据
|
|
|
- for _ in ad_plan_list:
|
|
|
- ad_plan_name = _['title']
|
|
|
- ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name,
|
|
|
- 'typesetting': json.dumps(_, ensure_ascii=False)}
|
|
|
- print('typesetting_info')
|
|
|
- print(_)
|
|
|
- print(ad_plan_typesetting_info)
|
|
|
- ad_plan_typesetting_inserte = sql_tools.save_ad_plan_typesetting_info(
|
|
|
- ad_plan_typesetting_info=ad_plan_typesetting_info,
|
|
|
- table_ad_plan_typesetting=ad_plan_typesetting_table)
|
|
|
- sql_session.execute(ad_plan_typesetting_inserte)
|
|
|
- sql_session.commit()
|
|
|
-
|
|
|
- # 2.2存行为记录
|
|
|
- task_name = 'user_id: {user_id} time:{time_sign} action:create_plan'.format(user_id=user_id,
|
|
|
- time_sign=datetime.now().strftime(
|
|
|
- "%Y-%m-%d, %H:%M:%S"))
|
|
|
- for _ in ad_plan_list:
|
|
|
- print(_)
|
|
|
- for action_type in [layout_create_action, ad_plan_create_action]:
|
|
|
- object_name = _['title'] if action_type == 'create_ad_plan' else _['idea']['jump_type_page_type'][
|
|
|
- 'layout_name']
|
|
|
- action_info = {'user_id': user_id, 'service_name': _['service_name'],
|
|
|
- 'wechat_name': _['wechat_name'],
|
|
|
- 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
|
|
|
- 'status': 'todo'}
|
|
|
- record_insert = sql_tools.save_action_record(action_record_info=action_info,
|
|
|
- table_action_record=action_record_table)
|
|
|
- sql_session.execute(record_insert)
|
|
|
- sql_session.commit()
|
|
|
# 4.开始运行
|
|
|
if not self.check_task(user_id=user_id):
|
|
|
+ # 1.查看是否cookie可用
|
|
|
+ log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
+
|
|
|
+ # 2.数据存入数据库
|
|
|
+ print(user_id, ad_plan_list)
|
|
|
+ if user_id is None or ad_plan_list is None:
|
|
|
+ self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
|
|
|
+ return
|
|
|
+ # 2.1存计划数据
|
|
|
+ for _ in ad_plan_list:
|
|
|
+ ad_plan_name = _['title']
|
|
|
+ ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name,
|
|
|
+ 'typesetting': json.dumps(_, ensure_ascii=False)}
|
|
|
+ print('typesetting_info')
|
|
|
+ print(_)
|
|
|
+ print(ad_plan_typesetting_info)
|
|
|
+ ad_plan_typesetting_inserte = sql_tools.save_ad_plan_typesetting_info(
|
|
|
+ ad_plan_typesetting_info=ad_plan_typesetting_info,
|
|
|
+ table_ad_plan_typesetting=ad_plan_typesetting_table)
|
|
|
+ sql_session.execute(ad_plan_typesetting_inserte)
|
|
|
+ sql_session.commit()
|
|
|
+
|
|
|
+ # 2.2存行为记录
|
|
|
+ task_name = 'user_id: {user_id} time:{time_sign} action:create_plan'.format(user_id=user_id,
|
|
|
+ time_sign=datetime.now().strftime(
|
|
|
+ "%Y-%m-%d, %H:%M:%S"))
|
|
|
+ for _ in ad_plan_list:
|
|
|
+ print(_)
|
|
|
+ for action_type in [layout_create_action, ad_plan_create_action]:
|
|
|
+ object_name = _['title'] if action_type == ad_plan_create_action else \
|
|
|
+ _['idea']['jump_type_page_type'][
|
|
|
+ 'layout_name']
|
|
|
+ action_info = {'user_id': user_id, 'service_name': _['service_name'],
|
|
|
+ 'wechat_name': _['wechat_name'],
|
|
|
+ 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
|
|
|
+ 'status': 'todo'}
|
|
|
+ record_insert = sql_tools.save_action_record(action_record_info=action_info,
|
|
|
+ table_action_record=action_record_table)
|
|
|
+ sql_session.execute(record_insert)
|
|
|
+ sql_session.commit()
|
|
|
threading.Thread(target=user_action.carry_plan,
|
|
|
- args=(user_id, ad_plan_list, log_ad, db, cookie_canuse)).start()
|
|
|
+ args=(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name)).start()
|
|
|
else:
|
|
|
self.write({'status': {'msg': '', "RetCode": 200}})
|
|
|
except Exception as e:
|
|
@@ -293,23 +293,24 @@ class ad_human_info(BaseHandler):
|
|
|
return
|
|
|
# TODO:一个涉及到selenium-driver的请求-生命周期.----看一下tornado是怎么处理请求的生命周期
|
|
|
if int(is_refresh) == 1:
|
|
|
- log_ad, cookie_canuse = self.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
- task_name = 'user_id: {user_id} time:{time_sign} action:refresh_wechat_info'.format(user_id=user_id,
|
|
|
- time_sign=datetime.now().strftime(
|
|
|
- "%Y-%m-%d, %H:%M:%S"))
|
|
|
- # 行为记录
|
|
|
- action_type = refresh_wechat_action
|
|
|
- object_name = ''
|
|
|
- service_name = ''
|
|
|
- wechat_name = ''
|
|
|
- action_info = {'user_id': user_id, 'service_name': service_name, 'wechat_name': wechat_name,
|
|
|
- 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
|
|
|
- 'status': 'todo'}
|
|
|
- record_insert = sql_tools.save_action_record(action_record_info=action_info,
|
|
|
- table_action_record=action_record_table)
|
|
|
- sql_session.execute(record_insert)
|
|
|
- sql_session.commit()
|
|
|
if not create_ad_plan.check_task(user_id=user_id):
|
|
|
+ log_ad, cookie_canuse = self.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
+ task_name = 'user_id: {user_id} time:{time_sign} action:refresh_wechat_info'.format(
|
|
|
+ user_id=user_id,
|
|
|
+ time_sign=datetime.now().strftime(
|
|
|
+ "%Y-%m-%d, %H:%M:%S"))
|
|
|
+ # 行为记录
|
|
|
+ action_type = refresh_wechat_action
|
|
|
+ object_name = ''
|
|
|
+ service_name = ''
|
|
|
+ wechat_name = ''
|
|
|
+ action_info = {'user_id': user_id, 'service_name': service_name, 'wechat_name': wechat_name,
|
|
|
+ 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
|
|
|
+ 'status': 'todo'}
|
|
|
+ record_insert = sql_tools.save_action_record(action_record_info=action_info,
|
|
|
+ table_action_record=action_record_table)
|
|
|
+ sql_session.execute(record_insert)
|
|
|
+ sql_session.commit()
|
|
|
threading.Thread(target=user_action.get_human_info,
|
|
|
args=(
|
|
|
user_id, log_ad, db, cookie_canuse)).start()
|
|
@@ -363,24 +364,25 @@ class ad_wechat_info(BaseHandler):
|
|
|
return
|
|
|
sql_session = db.DBSession()
|
|
|
if int(is_refresh) == 1:
|
|
|
- log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
- task_name = 'user_id: {user_id} time:{time_sign} action:refresh_wechat_info'.format(user_id=user_id,
|
|
|
- time_sign=datetime.now().strftime(
|
|
|
- "%Y-%m-%d, %H:%M:%S"))
|
|
|
- # 行为记录
|
|
|
- action_type = refresh_wechat_action
|
|
|
- object_name = ''
|
|
|
- service_name = ''
|
|
|
- wechat_name = ''
|
|
|
- action_info = {'user_id': user_id, 'service_name': service_name, 'wechat_name': wechat_name,
|
|
|
- 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
|
|
|
- 'status': 'todo'}
|
|
|
- record_insert = sql_tools.save_action_record(action_record_info=action_info,
|
|
|
- table_action_record=action_record_table)
|
|
|
- sql_session.execute(record_insert)
|
|
|
- sql_session.commit()
|
|
|
- #检查有无其他任务在处理中,有则等待
|
|
|
+ # 检查有无其他任务在处理中,有则等待
|
|
|
if not create_ad_plan.check_task(user_id=user_id):
|
|
|
+ log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
+ task_name = 'user_id: {user_id} time:{time_sign} action:refresh_wechat_info'.format(
|
|
|
+ user_id=user_id,
|
|
|
+ time_sign=datetime.now().strftime(
|
|
|
+ "%Y-%m-%d, %H:%M:%S"))
|
|
|
+ # 行为记录
|
|
|
+ action_type = refresh_wechat_action
|
|
|
+ object_name = ''
|
|
|
+ service_name = ''
|
|
|
+ wechat_name = ''
|
|
|
+ action_info = {'user_id': user_id, 'service_name': service_name, 'wechat_name': wechat_name,
|
|
|
+ 'action_type': action_type, 'object_name': object_name, 'task_name': task_name,
|
|
|
+ 'status': 'todo'}
|
|
|
+ record_insert = sql_tools.save_action_record(action_record_info=action_info,
|
|
|
+ table_action_record=action_record_table)
|
|
|
+ sql_session.execute(record_insert)
|
|
|
+ sql_session.commit()
|
|
|
threading.Thread(target=user_action.get_human_info,
|
|
|
args=(
|
|
|
user_id, log_ad, db, cookie_canuse)).start()
|