|
@@ -70,37 +70,43 @@ class create_ad_plan(BaseHandler):
|
|
|
# TODO:只要tornado开着就不允许修改数据库,------想好之后上线如何操作
|
|
|
# TODO:需要与刷新用户cookie相关action 联动,---------正在刷新用户信息时,不能进行计划创建.反之同理
|
|
|
def post(self):
|
|
|
- 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']
|
|
|
-
|
|
|
- # 1.查看是否cookie可用
|
|
|
- log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
-
|
|
|
- # 2.数据存入数据库
|
|
|
- print(user_id, ad_plan_list)
|
|
|
- sql_session = db.DBSession()
|
|
|
- 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'].replace(' ', '').replace('.','').replace(',','')[:29]
|
|
|
- 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)
|
|
|
+ try:
|
|
|
+ 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']
|
|
|
|
|
|
- # 4.开始运行
|
|
|
- threading.Thread(target=user_action.carry_plan,
|
|
|
- args=(user_id, ad_plan_list, log_ad, db, cookie_canuse)).start()
|
|
|
+ # 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'].replace(' ', '').replace('.','').replace(',','')[:29]
|
|
|
+ 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)
|
|
|
+
|
|
|
+ # 4.开始运行
|
|
|
+ threading.Thread(target=user_action.carry_plan,
|
|
|
+ args=(user_id, ad_plan_list, log_ad, db, cookie_canuse)).start()
|
|
|
+ except Exception as e:
|
|
|
+ self.write('eror')
|
|
|
+ try:
|
|
|
+ sql_session.commit()
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
class get_ad_plan_local(BaseHandler):
|
|
|
def get(self):
|
|
@@ -292,42 +298,47 @@ class ad_wechat_info(BaseHandler):
|
|
|
|
|
|
# 1.公众号相关信息获取
|
|
|
def get(self):
|
|
|
- # TODO:添加分页,
|
|
|
- # 公众号,服务商,唯一id设计或者获取
|
|
|
-
|
|
|
- # 0.是否刷新
|
|
|
- # 1.获取userid,以及是否刷新
|
|
|
- user_id = self.get_argument("user_id", None)
|
|
|
- is_refresh = self.get_argument("is_refresh", None)
|
|
|
- print(user_id, is_refresh)
|
|
|
- if user_id is None or is_refresh is None:
|
|
|
- self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
|
|
|
- return
|
|
|
- sql_session = db.DBSession()
|
|
|
- # TODO:一个涉及到selenium-driver的请求-生命周期.----看一下tornado是怎么处理请求的生命周期
|
|
|
- if int(is_refresh) == 1:
|
|
|
- log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
- threading.Thread(target=user_action.get_human_info,
|
|
|
- args=(
|
|
|
- user_id, log_ad, db, cookie_canuse)).start()
|
|
|
- else:
|
|
|
- # 1.查看是否在刷新,
|
|
|
- # 在刷新中,
|
|
|
- # 返回正在刷新
|
|
|
-
|
|
|
- # -------不管上面逻辑让他们多刷新几次
|
|
|
- # 不在刷新
|
|
|
- # 返回对应数据
|
|
|
- # 2.获取userid对应数据
|
|
|
- result = sql_tools.get_wechat_info(sql_session=sql_session, user_id=user_id)
|
|
|
- result_list = []
|
|
|
- for _ in result:
|
|
|
- service_name, wechat_name = _
|
|
|
- result_list.append({'service_name': service_name, 'wechat_name': wechat_name})
|
|
|
- print(result_list)
|
|
|
- self.write({'status': {'msg': 'success', "RetCode": 200},
|
|
|
- 'wechat_info': result_list})
|
|
|
+ try:
|
|
|
+ # TODO:添加分页,
|
|
|
+ # 公众号,服务商,唯一id设计或者获取
|
|
|
|
|
|
+ # 0.是否刷新
|
|
|
+ # 1.获取userid,以及是否刷新
|
|
|
+ user_id = self.get_argument("user_id", None)
|
|
|
+ is_refresh = self.get_argument("is_refresh", None)
|
|
|
+ print(user_id, is_refresh)
|
|
|
+ if user_id is None or is_refresh is None:
|
|
|
+ self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
|
|
|
+ return
|
|
|
+ sql_session = db.DBSession()
|
|
|
+ # TODO:一个涉及到selenium-driver的请求-生命周期.----看一下tornado是怎么处理请求的生命周期
|
|
|
+ if int(is_refresh) == 1:
|
|
|
+ log_ad, cookie_canuse = ad_human_info.refresh_wechat_cookies(self, user_id=user_id)
|
|
|
+ threading.Thread(target=user_action.get_human_info,
|
|
|
+ args=(
|
|
|
+ user_id, log_ad, db, cookie_canuse)).start()
|
|
|
+ else:
|
|
|
+ # 1.查看是否在刷新,
|
|
|
+ # 在刷新中,
|
|
|
+ # 返回正在刷新
|
|
|
+
|
|
|
+ # -------不管上面逻辑让他们多刷新几次
|
|
|
+ # 不在刷新
|
|
|
+ # 返回对应数据
|
|
|
+ # 2.获取userid对应数据
|
|
|
+ result = sql_tools.get_wechat_info(sql_session=sql_session, user_id=user_id)
|
|
|
+ result_list = []
|
|
|
+ for _ in result:
|
|
|
+ service_name, wechat_name = _
|
|
|
+ result_list.append({'service_name': service_name, 'wechat_name': wechat_name})
|
|
|
+ print(result_list)
|
|
|
+ self.write({'status': {'msg': 'success', "RetCode": 200},
|
|
|
+ 'wechat_info': result_list})
|
|
|
+ except Exception as e:
|
|
|
+ try:
|
|
|
+ sql_session.commit()
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
class delete_ad_layout(BaseHandler):
|
|
|
def get(self):
|