Explorar o código

MOD:计划--年龄修复

cxyu %!s(int64=3) %!d(string=hai) anos
pai
achega
154f5c6386

+ 9 - 30
web_module/tornado_api.py

@@ -52,7 +52,6 @@ class create_ad_plan_local(BaseHandler):
         user_id = request_dict['user_id']
         ad_plan_list = request_dict['plan_list']
 
-        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}})
@@ -85,7 +84,6 @@ class create_ad_plan(BaseHandler):
     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
@@ -94,9 +92,7 @@ class create_ad_plan(BaseHandler):
             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)
@@ -104,7 +100,6 @@ class create_ad_plan(BaseHandler):
         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'][
@@ -123,7 +118,6 @@ class create_ad_plan(BaseHandler):
         log_ad = None
         try:
             request_dict = json.loads(self.request.body, encoding='utf-8')
-            print(request_dict)
             ad_plan_list = request_dict['plan_list']
             user_id = request_dict['user_id']
             # 2.2存行为记录
@@ -140,12 +134,13 @@ class create_ad_plan(BaseHandler):
             else:
                 self.save_task_info(user_id, ad_plan_list, sql_session, task_name)
         except Exception as e:
+            if log_ad:
+                log_ad.driver.quit()
+
             logging.error(str(e))
             self.write('eror')
             raise
         finally:
-            if log_ad:
-                log_ad.driver.quit()
             sql_session.commit()
 
 
@@ -166,10 +161,8 @@ class get_ad_plan_local(BaseHandler):
             layout_name = ''
             result = sql_tools.get_plan_typesetting_rough(sql_session=sql_session, user_id=user_id,
                                                           typesetting_name=layout_name)
-        print(result)
         result_ = []
         for i in range(len(result)):
-            print(result[i])
             typesetting, name, create_time, update_time = result[i]
             _ = {}
             _['typesetting'] = json.loads(typesetting)
@@ -190,8 +183,6 @@ class create_ad_layout_local(BaseHandler):
         layout_typesetting = request_dict['layout_typesetting']
         layout_name = request_dict['layout_name']
 
-        print(user_id, layout_typesetting, layout_name)
-        print('layout-typesetting', type(layout_typesetting), layout_typesetting)
         sql_session = db.DBSession()
         if user_id is None or layout_name is None or layout_typesetting is None:
             self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
@@ -224,10 +215,8 @@ class get_ad_layout_local(BaseHandler):
             layout_name = ''
             result = sql_tools.get_layout_typesetting_rough(sql_session=sql_session, user_id=user_id,
                                                             typesetting_name=layout_name)
-        print(result)
         result_ = []
         for i in range(len(result)):
-            print(result[i])
             typesetting, name, create_time, update_time = result[i]
             _ = {}
             _['typesetting'] = json.loads(typesetting)
@@ -267,7 +256,7 @@ class ad_human_info(BaseHandler):
                 wechat_code = log_ad.log_in()
                 tornado_web.write({'status': {'msg': 'success', "RetCode": 200},
                                    'wechat_code': wechat_code})
-                print('cookie can not use')
+                logging.info('cookie can not use')
             else:
                 # cookie 可以继续使用
                 cookie_canuse = True
@@ -292,7 +281,6 @@ class ad_human_info(BaseHandler):
             is_refresh = self.get_argument("is_refresh", None)
             wechat_name = self.get_argument('wechat_name', None)
             service_name = self.get_argument('service_name', None)
-            print(user_id, is_refresh)
             if user_id is None or is_refresh is None or wechat_name is None or service_name is None:
                 self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
                 return
@@ -332,7 +320,6 @@ class ad_human_info(BaseHandler):
                 # 2.获取userid对应数据
                 result = sql_tools.get_human_info(sql_session=sql_session,
                                                   service_name=service_name, wechat_name=wechat_name)
-                print(result)
                 result = json.loads(result)
                 if human_package_name:
                     result = [_ for _ in result if human_package_name in _['name']]
@@ -344,12 +331,12 @@ class ad_human_info(BaseHandler):
                 self.write({'status': {'msg': 'success', "RetCode": 200},
                             'human_info': result})
         except Exception as e:
+            if log_ad:
+                log_ad.driver.quit()
             logging.error(str(e))
             raise
         finally:
             sql_session.commit()
-            if log_ad:
-                log_ad.driver.quit()
 
 
 class ad_wechat_info(BaseHandler):
@@ -366,7 +353,6 @@ class ad_wechat_info(BaseHandler):
             # 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
@@ -401,15 +387,14 @@ class ad_wechat_info(BaseHandler):
                 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:
+            if log_ad:
+                log_ad.driver.quit()
             logging.error(str(e))
             raise
         finally:
-            if log_ad:
-                log_ad.driver.quit()
             sql_session.commit()
 
 
@@ -459,7 +444,6 @@ class get_ad_wechat_service_name(BaseHandler):
         for _ in result:
             service_name = _
             result_list.append({'service_name': service_name})
-        print(result_list)
         self.write({'status': {'msg': 'success', "RetCode": 200},
                     'wechat_info': result_list})
 
@@ -479,7 +463,6 @@ class get_ad_wechat_wechat_name(BaseHandler):
         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})
 
@@ -502,7 +485,6 @@ class get_plan_action_record(BaseHandler):
                                            status=status, plan_name=plan_name)
         result_ = []
         for i in range(len(result)):
-            print(result[i])
             user_id, name, service_name, wechat_name, create_time, status, typesetting, wechat_id_info = result[i]
             _ = {}
             _['typesetting'] = json.loads(typesetting)
@@ -533,7 +515,6 @@ class get_all_ad_task(BaseHandler):
         localtion = ['wechat', '']
         for _ in result:
             task_name, status, task_status_num, create_time, typesetting = _
-            print(typesetting)
             typesetting = json.loads(typesetting)
             if typesetting['plan_base'][1] == 'pyq':
                 localtion[1] = 'pyq'
@@ -547,7 +528,6 @@ class get_all_ad_task(BaseHandler):
         for k, v in task_dict.items():
             # TODO:修改为dict的sort
             sum_num = 0
-            print(k, v)
             new_dict = {}
             create_time = None
             for k_, v_ in v.items():
@@ -561,7 +541,6 @@ class get_all_ad_task(BaseHandler):
                 {'task_name': k, 'task_info': new_dict, 'create_time': create_time, 'channel': localtion[0],
                  'localtion': localtion[1], 'id': num, 'status': status})
             num = num + 1
-        print(json.dumps(task_dict))
 
         self.write({'status': {'msg': 'success', "RetCode": 200},
                     'local_ad_plan_info': result_})

+ 3 - 4
web_module/user_action.py

@@ -50,7 +50,6 @@ def carry_plan(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name):
                         create_ad_layout = CreateAd(login_ad=log_ad, service_name=service_name, wechat_name=wechat_name)
                         layout_typesetting_dict = sql_tools.get_layout_typesetting(sql_session, user_id,
                                                                                    typesetting_name=layout_name)
-                        print(layout_typesetting_dict)
                         layout_typesetting_dict = json.loads(layout_typesetting_dict)
                         res = create_ad_layout.create_layout(layout_typesetting_dict)
                         sql_tools.action_record(res, sql_session, layout_create_action, user_id, layout_name,
@@ -58,7 +57,7 @@ def carry_plan(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name):
                                                 service_name, wechat_name, task_name)
                     except Exception as e:
                         res = {'sucess': False, 'result_info': str(e)}
-                        print('layout 创建失败', layout_create_action, res)
+                        logging.error('layout 创建失败', layout_create_action, res)
                         # 创建落地页,计划都失败
                         sql_tools.action_record(res, sql_session, layout_create_action, user_id, layout_name,
                                                 action_record_table,
@@ -103,7 +102,7 @@ def carry_plan(user_id, ad_plan_list, log_ad, db, cookie_canuse, task_name):
         logging.error(e)
         raise
     finally:
-        print('创建计划,任务结束')
+        logging.info('创建计划,任务结束')
         # 每次运行微信相关操作,对微信相关信息进行刷新
         sql_session.commit()
         log_ad.driver.quit()
@@ -212,7 +211,7 @@ def get_human_info(user_id, log_ad, db, cookie_canuse, task_name):
         logging.error(e)
         raise
     finally:
-        print('刷新用户,任务结束')
+        logging.info('刷新用户,任务结束')
         sql_session.commit()
         log_ad.driver.quit()
         check_task_in_hand(user_id=user_id, db=db)

+ 6 - 6
wechat_action/create_ad_plan.py

@@ -111,7 +111,6 @@ class CreateAdPlan():
         input_elements = self.driver.find_elements_by_xpath('//*[@class="adui-input-base"]')
 
         if self.task['date_set']['date_module'] == '2':
-            print(self.task['date_set']['date_list'])
             select_elements = self.driver.find_elements_by_xpath('//*[@class="adui-radio-base adui-radio-small"]')
             for _ in select_elements:
                 if '长期投放' in _.text:
@@ -256,18 +255,20 @@ class CreateAdPlan():
         # TODO:有时间规整一下,前端传过来的数据,dict中的值  数字全为字符串,或者全为数字
 
         # 256,一截,[14(17),24][25,32][33,40][41,48][49,56][57,64]
+        # 8 为基本下滑单位,+1为实际两数相减需要加一, -0.1因为刚刚好最后一位时就会下滑到下一页,最后一位无法获取
         if age_list[0] == 14:
+
             age_elements[1].click()
             time.sleep(random.uniform(0.1, 0.2))
             self.driver.execute_script('''
                             document.getElementsByClassName('rc-virtual-list-holder')[0].scrollTop={};
-                            '''.format(((age_list[1] - 17) / 7) * 256))
+                            '''.format(((age_list[1] - 17 + 1 - 0.1) / 8) * 256))
             self.driver.find_element_by_xpath('//*[@id="end_age_{}"]'.format(int(age_list[1]))).click()
 
         else:
             self.driver.execute_script('''
             document.getElementsByClassName('rc-virtual-list-holder')[0].scrollTop={};
-            '''.format(int((age_list[0] - 17) / 7) * 256))
+            '''.format(int((age_list[0] - 17 + 1 - 0.1) / 8) * 256))
             time.sleep(random.uniform(0.1, 0.2))
             self.driver.find_element_by_xpath('//*[@id="begin_age_{}"]'.format(int(age_list[0]))).click()
 
@@ -275,8 +276,8 @@ class CreateAdPlan():
             age_elements[1].click()
             time.sleep(random.uniform(0.1, 0.2))
             self.driver.execute_script('''
-                document.getElementsByClassName('rc-virtual-list-holder')[0].scrollTop={};
-                '''.format(int((age_list[1] - 17) / 7) * 256))
+                document.getElementsByClassName('rc-virtual-list-holder')[1].scrollTop={};
+                '''.format(int((age_list[1] - age_list[0] + 1 - 0.1) / 8) * 256))
             time.sleep(random.uniform(0.1, 0.2))
             self.driver.find_element_by_xpath('//*[@id="end_age_{}"]'.format(int(age_list[1]))).click()
 
@@ -332,7 +333,6 @@ class CreateAdPlan():
         plan_check_url = 'https://mp.weixin.qq.com/promotion/as_rock?action=get_campaign_data&args={"op_type":1,"where":{},"page":1,"page_size":20,"pos_type":999,"ad_filter":{"name":"' \
                          + plan_name + '"},"advanced":true,"create_time_range":{"start_time":1610884851},"time_range":{"start_time":1610748800,"last_time":' + time_small + '}}&token=' + token + '&appid=&spid=&_=' + time_big
         rsp = requests.get(plan_check_url, cookies=cookie_dict)
-        print(rsp.text)
         if 'list' in rsp.json():
             if len(rsp.json()['list']):
                 return True

+ 0 - 17
wechat_action/sql_tools.py

@@ -42,8 +42,6 @@ def save_layout_typesetting_info(layout_typesetting_info, table_layout_typesetti
 
 def save_ad_plan_typesetting_info(ad_plan_typesetting_info, table_ad_plan_typesetting):
     # TODO:正常action_record  返回plan_name layout_name有问题
-    for k, v in ad_plan_typesetting_info.items():
-        print(k, v)
     insert_ad_plan_typesetting = table_ad_plan_typesetting.insert()
     insert_ad_plan_typesetting = insert_ad_plan_typesetting.values \
         (typesetting=ad_plan_typesetting_info['typesetting'],
@@ -106,7 +104,6 @@ def get_layout_typesetting_rough(sql_session, user_id, typesetting_name):
             select typesetting,name,create_time,update_time from layout_typesetting lt 
             where user_id ='{}' and is_delete=0 and name like '%{}%';
     '''.format(user_id, typesetting_name)
-    print(sql)
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
     result_list = [line for line in lines]
@@ -118,7 +115,6 @@ def get_layout_typesetting(sql_session, user_id, typesetting_name):
             select typesetting from layout_typesetting lt 
             where user_id ='{}' and is_delete=0 and name='{}' ;
     '''.format(user_id, typesetting_name)
-    print(sql)
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
     if lines:
@@ -132,7 +128,6 @@ def delete_layout_typesetting_vir(sql_session, user_id, typesetting_name):
             set is_delete=1
             where user_id ='{}' and name = '{}';
     '''.format(user_id, typesetting_name)
-    print(sql)
     sql_session.execute(sql)
     sql_session.commit()
 
@@ -142,7 +137,6 @@ def get_plan_typesetting_rough(sql_session, user_id, typesetting_name):
             select typesetting,name,create_time,update_time from ad_plan_typesetting lt 
             where user_id ='{}'  and name like '%{}%';
     '''.format(user_id, typesetting_name)
-    print(sql)
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
     result_list = [line for line in lines]
@@ -170,7 +164,6 @@ def delete_ad_plan_typesetting_vir(sql_session, user_id, typesetting_name, wecha
             wechat_name='{wechat_name}' and service_name='{service_name}';
     '''.format(user_id=user_id, name=typesetting_name,
                service_name=service_name, wechat_name=wechat_name)
-    print(sql)
     sql_session.execute(sql)
     sql_session.commit()
 
@@ -205,7 +198,6 @@ def get_plan_record(sql_session, user_id, service_name, wechat_name,
         ) as foo left join wechat_info 
         on foo.service_name =wechat_info.service_name and foo.wechat_name = wechat_info.wechat_name ;
     '''.format(user_id=user_id, other_info=other_info)
-    print(sql)
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
     result = [line for line in lines]
@@ -235,8 +227,6 @@ def get_task_in_hand_num(user_id, sql_session):
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
     result = lines[0][0]
-    print(sql)
-    print(result)
     return result
 
 
@@ -313,11 +303,7 @@ def get_action_status(sql_session, user_id):
 
 def action_record(res, sql_session, action_type, user_id, object_name, action_table, service_name,
                   wechat_name, task_name):
-    print('get in action record ', service_name, wechat_name, res)
     status = 'done' if res['sucess'] else 'error'
-    print('get in action record ', action_type, user_id, object_name, service_name,
-          wechat_name, task_name, res['result_info'])
-    print(action_type)
     update_res = action_table.update() \
         .where(action_table.c.service_name == service_name) \
         .where(action_table.c.wechat_name == wechat_name) \
@@ -344,7 +330,6 @@ def check_layout_alive(sql_session, service_name, wechat_name, layout_name):
         and action_type like '%{layout_name}%'
         and status='done'
     '''.format(service_name=service_name, wechat_name=wechat_name, layout_name=layout_name)
-    print(sql)
     cursor = sql_session.execute(sql)
     num = cursor.fetchall()[0][0]
     return num
@@ -359,7 +344,6 @@ def check_plan_alive(sql_session, service_name, wechat_name, plan_name):
            and action_type like '%{plan_name}%'
            and status='done'
        '''.format(service_name=service_name, wechat_name=wechat_name, plan_name=plan_name)
-    print('plan ', sql)
     cursor = sql_session.execute(sql)
     num = cursor.fetchall()[0][0]
     return num
@@ -404,6 +388,5 @@ def get_wechat_cookies(sql_session, user_id):
     '''.format(user_id)
     cursor = sql_session.execute(sql)
     lines = cursor.fetchall()
-    print(type(lines), lines)
     if lines:
         return lines[0][0]