cxyu преди 3 години
родител
ревизия
fd70a8f82c
променени са 2 файла, в които са добавени 44 реда и са изтрити 44 реда
  1. 32 32
      app/api_data/tx_ad_cost/cost_util.py
  2. 12 12
      model/DataBaseOperation.py

+ 32 - 32
app/api_data/tx_ad_cost/cost_util.py

@@ -55,7 +55,7 @@ def get_campaign(account_id, access_token, flag,campaign_ids,dt):
                 time.sleep(61)
             else:
                 break
-        # print(r)
+        # logging.info(r)
         total_page = r['data']['page_info']['total_page']
 
         if page > total_page:
@@ -70,10 +70,10 @@ def get_campaign(account_id, access_token, flag,campaign_ids,dt):
                            DateUtils.stamp_to_str(i['created_time']),
                            DateUtils.stamp_to_str(i['last_modified_time']),i.get('speed_mode'),i.get('is_deleted'),
                            account_id, flag, dt))
-    # print(li)
+    # logging.info(li)
     """mp 没有 speed_mode,is_deleted,budget_reach_date"""
     if li.__len__() > 0:
-        print(f"{account_id}有计划:", li.__len__())
+        logging.info(f"{account_id}有计划:", li.__len__())
         sql = "replace into campaign_info values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
         db.quchen_text.executeMany(sql, li)
     db.close()
@@ -114,22 +114,22 @@ def get_adcreatives(account_id,access_token,flag,adc_ids,dt):  # 获取创意
 
         while True:
             h = requests.get(url, params=parameters)
-            # print(h.json())
+            # logging.info(h.json())
 
             if h.status_code == 200:
                 r = h.json()
-                # print(r)
+                # logging.info(r)
 
                 break
             else:
                 time.sleep(1)
-                print("爬取失败 等待1s")
+                logging.info("爬取失败 等待1s")
 
 
         if 'data' in r.keys():
             is_video=0
             for i in r['data']['list']:
-                # print(i)
+                # logging.info(i)
 
                 if flag=='MP':
                     if len(i['adcreative_elements'])>0:
@@ -195,7 +195,7 @@ def get_adcreatives(account_id,access_token,flag,adc_ids,dt):  # 获取创意
         else:
             break
     if len(li)>0:
-        print(f"{account_id}有创意:",len(li))
+        logging.info(f"{account_id}有创意:",len(li))
         sql='replace into adcreative_info values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) '
         db.quchen_text.executeMany(sql,li)
 
@@ -239,13 +239,13 @@ def images_info_get(account_id,access_token,image_ids):  # 获取图片信息
 
         while True:
             h = requests.get(url, params=parameters)
-            # print(h.text)
+            # logging.info(h.text)
             if h.status_code == 200:
                 r = h.json()
                 break
             else:
                 time.sleep(1)
-                print("请求出错 等待1s..")
+                logging.info("请求出错 等待1s..")
 
         if 'data' in r.keys():
             li.extend(r['data']['list'])
@@ -256,12 +256,12 @@ def images_info_get(account_id,access_token,image_ids):  # 获取图片信息
             page += 1
         else:
             break
-    # print(li)
+    # logging.info(li)
     data = []
     for i in li:
         data.append((i['image_id'],i['width'],i['height'],i['signature'],i['preview_url']))
-    # print(data)
-    print(f"{account_id} 有图片:", li.__len__())
+    # logging.info(data)
+    logging.info(f"{account_id} 有图片:", li.__len__())
     if li.__len__() > 0:
         sql="replace into image_info value (%s,%s,%s,%s,%s)"
         db.quchen_text.executeMany(sql, data)
@@ -306,13 +306,13 @@ def video_info_get(account_id,access_token,image_ids):  # 获取视频信息
 
         while True:
             h = requests.get(url, params=parameters)
-            # print(h.text)
+            # logging.info(h.text)
             if h.status_code == 200:
                 r = h.json()
                 break
             else:
                 time.sleep(1)
-                print("请求出错 等待1s..")
+                logging.info("请求出错 等待1s..")
 
         if 'data' in r.keys():
             li.extend(r['data']['list'])
@@ -323,12 +323,12 @@ def video_info_get(account_id,access_token,image_ids):  # 获取视频信息
             page += 1
         else:
             break
-    # print(li)
+    # logging.info(li)
     data = []
     for i in li:
         data.append((i['video_id'],i['width'],i['height'],i['signature'],i['preview_url']))
-    # print(data)
-    print(f"{account_id} 有视频:", li.__len__())
+    # logging.info(data)
+    logging.info(f"{account_id} 有视频:", li.__len__())
     if li.__len__() > 0:
         sql="replace into video_info value (%s,%s,%s,%s,%s)"
         db.quchen_text.executeMany(sql, data)
@@ -345,14 +345,14 @@ def ad_info():
     total_data =[]
     executor = ThreadPoolExecutor(max_workers=max_workers)
     for i in accounts:
-        # print(i)
+        # logging.info(i)
         account_id =i[0]
         access_token = i[1]
         type = i[3]
         executor.submit(get_ad_info,account_id, access_token,type,total_data)
     executor.shutdown()
 
-    print(len(total_data))
+    logging.info(len(total_data))
     if len(total_data)>0:
         sql="replace into ad_info values(%s,%s,%s,%s,%s,%s,%s) "
         db.quchen_text.executeMany(sql, total_data)
@@ -399,7 +399,7 @@ def get_ad_info(account_id, access_token, flag,ad_ids,dt):
                 time.sleep(61)
             else:
                 break
-        # print(r)
+        # logging.info(r)
         total_page = r['data']['page_info']['total_page']
 
         if page > total_page:
@@ -414,7 +414,7 @@ def get_ad_info(account_id, access_token, flag,ad_ids,dt):
 
 
     if li.__len__()>0:
-        print(f"{account_id}有广告:",li.__len__())
+        logging.info(f"{account_id}有广告:",li.__len__())
         sql = "replace into ad_info values(%s,%s,%s,%s,%s,%s,%s,%s) "
         db.quchen_text.executeMany(sql, li)
     db.close()
@@ -457,7 +457,7 @@ def ad_cost_day_gdt(account_id,access_token,st,et):
 
         while True:
             r  = requests.get(url, params=parameters).json()
-        # print(r)
+        # logging.info(r)
             code =r['code']
             if code==11017:
                 time.sleep(61)
@@ -479,9 +479,9 @@ def ad_cost_day_gdt(account_id,access_token,st,et):
             break
         else:
             page += 1
-    # print(li)
+    # logging.info(li)
     if len(li) > 0:
-        print(f"{account_id} have ad cost :{len(li)} ")
+        logging.info(f"{account_id} have ad cost :{len(li)} ")
         db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li)
         db.close()
 
@@ -513,9 +513,9 @@ def ad_cost_day_mp(account_id,access_token,st,et):
 
         while True:
             r = requests.get(url, params=parameters).json()
-            # print(r['data']['list'])
+            # logging.info(r['data']['list'])
             # import pandas as pd
-            # print(pd.DataFrame(r['data']['list']))
+            # logging.info(pd.DataFrame(r['data']['list']))
 
             code = r['code']
             if code == 11017:
@@ -539,10 +539,10 @@ def ad_cost_day_mp(account_id,access_token,st,et):
             break
         else:
             page += 1
-    # print(li)
+    # logging.info(li)
     # exit()
     if len(li) > 0:
-        print(f"{account_id} have ad cost :{len(li)} ")
+        logging.info(f"{account_id} have ad cost :{len(li)} ")
         db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li)
         db.close()
 
@@ -586,7 +586,7 @@ def daily_reports_get(access_token, account_id, level, start_date, end_date, fie
             break
         else:
             time.sleep(1)
-            print("请求出错 等待1s..")
+            logging.info("请求出错 等待1s..")
 
     return r.json()
 
@@ -652,10 +652,10 @@ def mysql_insert_adcreative(data):
         cursor.executemany(sql, data)
         db.commit()
 
-        print('insert [adcreative] ', len(data))
+        logging.info('insert [adcreative] ', len(data))
     except:
         db.rollback()
-        print('insert [adcreative] defeat')
+        logging.info('insert [adcreative] defeat')
 
 
 

+ 12 - 12
model/DataBaseOperation.py

@@ -83,7 +83,7 @@ class MysqlOperation:
         #
         #     # log.info('sql: \n' + sql)
         #     log.info('sql cost: %s' % (time.time() - start))
-        print(f"affect rows :{k}")
+        log.info(f"affect rows :{k}")
 
 
 
@@ -94,7 +94,7 @@ class MysqlOperation:
         # if MYSQL_DEBUG:
         #     log.info('sql: \n' + sql)
         #     log.info('sql cost: %s' % (time.time() - start))
-        print(f"\033[1;36maffect rows :{k} \033[0m")
+        log.info(f"\033[1;36maffect rows :{k} \033[0m")
 
     def getOne(self,sql, args=None):
         result = self.getData(sql, args)
@@ -334,7 +334,7 @@ class MysqlOperation:
             # sql_condition_old = """(%s)=(%s)""" % (','.join(keys), ','.join(['%s'] * len(key_values[i])))
             row_condition_list = map(lambda x: '%s = %%s' % x, keys)
             sql_condition = """(%s)""" % ' and '.join(row_condition_list)
-            # print sql_condition_old, sql_condition
+            # log.info sql_condition_old, sql_condition
             list_sql_condition.append(sql_condition)
             list_tmp.extend(key_values[i])
         sql_where = ' or '.join(list_sql_condition)
@@ -352,7 +352,7 @@ class MysqlOperation:
             log.info(sql % tuple(list_tmp))
 
         self.cursor.execute(sql, tuple(list_tmp))
-        print()
+        log.info()
         result = self.cursor.fetchall()
         return map(lambda x: x[0], result)
 
@@ -423,7 +423,7 @@ class MysqlOperation:
                 self.updateManyV2(table, keys, tags, tag_values[start:finish], key_values[start:finish], flag, split=split)
             return
         if len(key_values) == 0 or len(tag_values) == 0:
-            log.debug('update 0 rows')
+            log.info('update 0 rows')
             return
         tag_values = self._convert_to_list(tag_values)
         key_values = self._convert_to_list(key_values)
@@ -520,7 +520,7 @@ class MysqlOperation:
             where %s in %s
         """ % (table, sql_keys, contact_s)
         if flag:
-            log.debug(sql_del % tuple(values_s))
+            log.info(sql_del % tuple(values_s))
         self.cursor.execute(sql_del, tuple(values_s))
         self.conn.commit()
 
@@ -541,7 +541,7 @@ class MysqlOperation:
         values ('2017-01-01', 10, 1, 'a'), ('2017-01-02', 20, 2, 'b'), ...
         """
         if len(key_values) == 0 or len(tag_values) == 0:
-            log.debug('insert 0 rows')
+            log.info('insert 0 rows')
             return
         if len(tag_values) > split:
             length = len(tag_values)
@@ -563,11 +563,11 @@ class MysqlOperation:
         for _ in zip(key_values, tag_values):
             value_insert.extend(_[0] + _[1])
         if flag:
-            log.debug(sql_insert % tuple(value_insert))
+            log.info(sql_insert % tuple(value_insert))
         t0 = time.time()
 
         self.cursor.execute(sql_insert,tuple(value_insert))
-        log.debug('insert %s rows, cost: %s' % (len(key_values), round(time.time() - t0, 2)))
+        log.info('insert %s rows, cost: %s' % (len(key_values), round(time.time() - t0, 2)))
         self.conn.commit()
 
     def update_many(self, table, keys, tags, tag_values, key_values, flag=False, split=80):
@@ -611,7 +611,7 @@ class MysqlOperation:
                 self.update_many(table, keys, tags, tag_values[start:finish], key_values[start:finish], flag, split=split)
             return
         if len(key_values) == 0 or len(tag_values) == 0:
-            log.debug('update 0 rows')
+            log.info('update 0 rows')
             return
 
         tag_values = self._convert_to_list(tag_values)
@@ -652,14 +652,14 @@ class MysqlOperation:
         sql_where = ' or '.join(list_sql_condition)
 
         # condition = ' or\n\t'.join([sql_keys + '=' + sql_key_values] * len(tag_values))
-        # print condition
+        # log.info condition
         sql = """update %s\n set %s\n where %s""" % (table, sql_set_concat, sql_where)
         if flag:
             log.info(sql % tuple(update_value))
         t0 = time.time()
         self.cursor.execute(sql, tuple(update_value))
         self.conn.commit()
-        log.debug('update %s rows, cost: %s' % (len(key_values), round(time.time() - t0, 2)))
+        log.info('update %s rows, cost: %s' % (len(key_values), round(time.time() - t0, 2)))
 
 
     def getColumn(self,table,flag=0):