|
@@ -82,6 +82,42 @@ class create_ad_plan(BaseHandler):
|
|
result = sql_tools.get_task_in_hand_num(user_id, sql_session)
|
|
result = sql_tools.get_task_in_hand_num(user_id, sql_session)
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
+ def save_task_info(self, user_id, ad_plan_list, sql_session, task_name):
|
|
|
|
+
|
|
|
|
+ # 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()
|
|
|
|
+
|
|
|
|
+ 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()
|
|
|
|
+
|
|
def post(self):
|
|
def post(self):
|
|
try:
|
|
try:
|
|
sql_session = db.DBSession()
|
|
sql_session = db.DBSession()
|
|
@@ -89,52 +125,21 @@ class create_ad_plan(BaseHandler):
|
|
print(request_dict)
|
|
print(request_dict)
|
|
ad_plan_list = request_dict['plan_list']
|
|
ad_plan_list = request_dict['plan_list']
|
|
user_id = request_dict['user_id']
|
|
user_id = request_dict['user_id']
|
|
-
|
|
|
|
|
|
+ # 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"))
|
|
# 4.开始运行
|
|
# 4.开始运行
|
|
if not self.check_task(user_id=user_id):
|
|
if not self.check_task(user_id=user_id):
|
|
# 1.查看是否cookie可用
|
|
# 1.查看是否cookie可用
|
|
log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
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()
|
|
|
|
|
|
+ self.save_task_info(user_id, ad_plan_list, sql_session, task_name)
|
|
threading.Thread(target=user_action.carry_plan,
|
|
threading.Thread(target=user_action.carry_plan,
|
|
args=(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name)).start()
|
|
args=(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name)).start()
|
|
|
|
+ else:
|
|
|
|
+ self.save_task_info(user_id, ad_plan_list, sql_session, task_name)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ raise
|
|
logging.error(str(e))
|
|
logging.error(str(e))
|
|
|
|
|
|
self.write('eror')
|
|
self.write('eror')
|