Ver Fonte

Merge branch 'yifan' of ASJ_ADS/sync_amz_data into master

yifan_huang96 há 6 meses atrás
pai
commit
a7c9dd9d6b
2 ficheiros alterados com 20 adições e 17 exclusões
  1. 19 16
      start_sync_amz.py
  2. 1 1
      sync_amz_data/settings/__init__.py

+ 19 - 16
start_sync_amz.py

@@ -231,22 +231,25 @@ def func_2(delete_list):
                 except:
                     locals()[table_name] = conn.query_df(
                         f"select date,SUM(sales14d) as sales14d  from AmazonReport.`{table_name}` date >='{check_date}' group by date,profileId")
-        locals()[table_name].columns = ['date', 'refer_']
-        locals()[table_name]['refer_'] = locals()[table_name]['refer_'].astype('float64')
-        todayMinus2 = (datetime.today().date() + timedelta(days=-2))
-        reback_21days = (todayMinus2 + timedelta(days=-8)).isoformat()
-        df = pd.date_range(start=reback_21days, end=todayMinus2.isoformat(), freq='1d')
-        df1 = pd.DataFrame(df, columns=['date_'])
-        merge_df = df1.merge(locals()[table_name], left_on=['date_'], right_on=['date'], how='left')
-        rel = merge_df.query("date_!=date or refer_<1 or refer_.isna()")['date_'].map(
-            lambda x: x.date().isoformat()).tolist()
-        print(rel, date_list)
-        if len(rel) > 0:
-            for date in rel:
-                date_list.extend([date])
-                conn = SP_ETL(**AWS_CREDENTIALS).clickhouse_connect()
-                conn.command(
-                    f"delete from AmazonReport.`{table_name}` where date='{date}' and profileId='{AWS_CREDENTIALS['profile_id']}'")
+        try:
+            locals()[table_name].columns = ['date', 'refer_']
+            locals()[table_name]['refer_'] = locals()[table_name]['refer_'].astype('float64')
+            todayMinus2 = (datetime.today().date() + timedelta(days=-2))
+            reback_21days = (todayMinus2 + timedelta(days=-8)).isoformat()
+            df = pd.date_range(start=reback_21days, end=todayMinus2.isoformat(), freq='1d')
+            df1 = pd.DataFrame(df, columns=['date_'])
+            merge_df = df1.merge(locals()[table_name], left_on=['date_'], right_on=['date'], how='left')
+            rel = merge_df.query("date_!=date or refer_<1 or refer_.isna()")['date_'].map(
+                lambda x: x.date().isoformat()).tolist()
+            print(rel, date_list)
+            if len(rel) > 0:
+                for date in rel:
+                    date_list.extend([date])
+                    conn = SP_ETL(**AWS_CREDENTIALS).clickhouse_connect()
+                    conn.command(
+                        f"delete from AmazonReport.`{table_name}` where date='{date}' and profileId='{AWS_CREDENTIALS['profile_id']}'")
+        except Exception as e:
+            print(e)
 
     return date_list
 

+ 1 - 1
sync_amz_data/settings/__init__.py

@@ -61,7 +61,7 @@ LOG_CONF = {
             'mailhost': ('email-smtp.us-east-1.amazonaws.com', 587),
             'fromaddr': 'datalab@ansjer.com',
             'toaddrs': [
-                'yifan_huang96@hotmail.com',
+                '1067279008@qq.com',
             ],
             'subject': 'sync_amz_data',
             'credentials': ('AKIARBAGHTGOTVILWLB7', 'BEVt2GkzivI0xhnLWgwJCT2k7lDSg8HW+APD3mc4uHVg'),