huangyifan 1 year ago
parent
commit
00b1351527
1 changed files with 29 additions and 26 deletions
  1. 29 26
      sync_get_order_data.py

+ 29 - 26
sync_get_order_data.py

@@ -7,26 +7,29 @@ from sync_amz_data.public import sp_api_client
 from datetime import datetime,timedelta
 
 def func_run():
+    # try:
+    #     for days in (-2,-3):
+    #
+    #         sp_api_client.SpApiRequest.get_allShops("GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL",days=days,**{})
+    #         time.sleep(5)
+    # except Exception as e:
+    #     print(e)
     try:
-        for days in (-2,-3):
-
-            sp_api_client.SpApiRequest.get_allShops("GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL",days=days,**{})
-            time.sleep(5)
-    except Exception as e:
-        print(e)
-    try:
-        for days in (-2,-12,-1): #range(-3,-63,-1):
-            conn = sp_api_client.SpApiRequest.Data_auth()
-            cursor = conn.cursor()
-            delete_date = (datetime.now() + timedelta(days=days-7)).strftime("%Y-%m-%d")
-            cursor.execute(f"delete from asj_ads.SalesAndTrafficByAsin where data_date='{delete_date}'")
-            conn.commit()
-            sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "CHILD"})
-            time.sleep(3.5)
-            sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "SKU"})
-            time.sleep(3.5)
-            sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "PARENT"})
-            time.sleep(3.5)
+        count = 0
+        for days in range(-4,-63,-1): #range(-2,-10,-1): #
+            if count in [i for i in range(0,32)]:
+                conn = sp_api_client.SpApiRequest.Data_auth()
+                cursor = conn.cursor()
+                delete_date = (datetime.now() + timedelta(days=days-7)).strftime("%Y-%m-%d")
+                cursor.execute(f"delete from asj_ads.SalesAndTrafficByAsin where data_date='{delete_date}'")
+                conn.commit()
+                sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "CHILD"})
+                time.sleep(3.5)
+                sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "SKU"})
+                time.sleep(3.5)
+                sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "PARENT"})
+                time.sleep(3.5)
+                count+=1
 
             sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days, **{"level": "CHILD"})
             time.sleep(3.5)
@@ -39,13 +42,13 @@ def func_run():
         print(e)
 
 
-# func_run()
-if __name__ == '__main__':
-
-    sched = BlockingScheduler()
-    sched.add_job(func_run, 'cron', hour=0, minute=0,
-                  second=30)
-    sched.start()
+func_run()
+# if __name__ == '__main__':
+#
+#     sched = BlockingScheduler()
+#     sched.add_job(func_run, 'cron', hour=0, minute=0,
+#                   second=30)
+#     sched.start()