huangyifan 1 year ago
parent
commit
1c7c59e7ec
2 changed files with 19 additions and 15 deletions
  1. 5 8
      sync_get_open_listing_data.py
  2. 14 7
      sync_get_order_data.py

+ 5 - 8
sync_get_open_listing_data.py

@@ -512,14 +512,10 @@ class SpApiRequest:
                 imageurl = temp_df['image_link']
                 imageurl = temp_df['image_link']
                 temp = df_rel.query("""listing_id==@listing_id and asin==@asin and sku==@sku and quantity==@quantity and fulfillment_channel==@fulfillment_channel and price==@price and product_id==@product_id and country_code==@country_code and seller_id==@seller_id and title==@title and image_link==@imageurl""")
                 temp = df_rel.query("""listing_id==@listing_id and asin==@asin and sku==@sku and quantity==@quantity and fulfillment_channel==@fulfillment_channel and price==@price and product_id==@product_id and country_code==@country_code and seller_id==@seller_id and title==@title and image_link==@imageurl""")
                 print("需要关注数据(是否异常):",len(temp),temp.to_numpy().tolist()) if len(temp)>1 else 1
                 print("需要关注数据(是否异常):",len(temp),temp.to_numpy().tolist()) if len(temp)>1 else 1
-                if len(temp)>1:
-                    # temp = temp.head(1).to_numpy().tolist()
-                    df_data = df_data.append(temp_df, ignore_index=True)
-                    delete_list.append((seller_id, marketplace_id, sku, listing_id, product_id))
-                # print(len(temp))
-                elif len(temp)==0:
-                    df_data = df_data.append(temp_df,ignore_index=True)
-                    delete_list.append((seller_id,marketplace_id,sku,listing_id,product_id))
+
+                df_data = df_data.append(temp_df, ignore_index=True)
+                delete_list.append((seller_id, marketplace_id, sku, listing_id, product_id))
+
                 row += 1
                 row += 1
             print("判断不同数据条数",len(delete_list))
             print("判断不同数据条数",len(delete_list))
             print("预计更新数据条数",len(df_data))
             print("预计更新数据条数",len(df_data))
@@ -722,6 +718,7 @@ class SpApiRequest:
 def func_run():
 def func_run():
     SpApiRequest.get_allShops("GET_FLAT_FILE_OPEN_LISTINGS_DATA")
     SpApiRequest.get_allShops("GET_FLAT_FILE_OPEN_LISTINGS_DATA")
 
 
+# func_run()
 if __name__ == '__main__':
 if __name__ == '__main__':
     sched = BlockingScheduler()
     sched = BlockingScheduler()
     sched.add_job(func_run,'cron',hour=1,minute=30,second=0)
     sched.add_job(func_run,'cron',hour=1,minute=30,second=0)

+ 14 - 7
sync_get_order_data.py

@@ -702,8 +702,13 @@ class SpApiRequest:
         # print(list_df)
         # print(list_df)
         # print(list_df[0])
         # print(list_df[0])
         # tuple_data = [tuple(i) for i in list_df]
         # tuple_data = [tuple(i) for i in list_df]
-        conn = self.mysql_connect_auth_lst()
-        cursor = conn.cursor()
+        try:
+            conn = self.mysql_connect_auth_lst()
+            cursor = conn.cursor()
+        except:
+            time.sleep(5)
+            conn = self.mysql_connect_auth_lst()
+            cursor = conn.cursor()
         # print(list(conn.query("select * from amz_sp_api.orderReport")))
         # print(list(conn.query("select * from amz_sp_api.orderReport")))
         sql = f"""
         sql = f"""
             insert into asj_ads.orderReport
             insert into asj_ads.orderReport
@@ -715,6 +720,8 @@ class SpApiRequest:
             cursor.executemany(sql,list_df)
             cursor.executemany(sql,list_df)
             conn.commit()
             conn.commit()
             print("插入完成")
             print("插入完成")
+            conn.close()
+            time.sleep(1)
         except Exception as e:
         except Exception as e:
             conn.rollback()
             conn.rollback()
             print(e)
             print(e)
@@ -725,11 +732,11 @@ def func_run():
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    func_run()
-    # sched = BlockingScheduler()
-    # sched.add_job(func_run, 'cron', hour=0, minute=0,
-    #               second=30)
-    # sched.start()
+    # func_run()
+    sched = BlockingScheduler()
+    sched.add_job(func_run, 'cron', hour=0, minute=0,
+                  second=30)
+    sched.start()
 
 
 
 
 """
 """