sync_get_order_data.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import time
  2. import warnings
  3. warnings.filterwarnings('ignore')
  4. from apscheduler.schedulers.blocking import BlockingScheduler
  5. from sync_amz_data.settings import MYSQL_AUTH_CONF, MYSQL_DATA_CONF
  6. from sync_amz_data.public import sp_api_client
  7. from datetime import datetime,timedelta
  8. def func_run():
  9. # try:
  10. # for days in (-2,-3):
  11. #
  12. # sp_api_client.SpApiRequest.get_allShops("GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL",days=days,**{})
  13. # time.sleep(5)
  14. # except Exception as e:
  15. # print(e)
  16. try:
  17. count = 0
  18. for days in range(-4,-63,-1): #range(-2,-10,-1): #
  19. if count in [i for i in range(0,32)]:
  20. conn = sp_api_client.SpApiRequest.Data_auth()
  21. cursor = conn.cursor()
  22. delete_date = (datetime.now() + timedelta(days=days-7)).strftime("%Y-%m-%d")
  23. cursor.execute(f"delete from asj_ads.SalesAndTrafficByAsin where data_date='{delete_date}'")
  24. conn.commit()
  25. sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "CHILD"})
  26. time.sleep(3.5)
  27. sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "SKU"})
  28. time.sleep(3.5)
  29. sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days-7, **{"level": "PARENT"})
  30. time.sleep(3.5)
  31. count+=1
  32. sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT", days=days, **{"level": "CHILD"})
  33. time.sleep(3.5)
  34. sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT",days=days,**{"level":"SKU"})
  35. time.sleep(3.5)
  36. sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT",days=days,**{"level":"PARENT"})
  37. time.sleep(3.5)
  38. except Exception as e:
  39. print(e)
  40. func_run()
  41. # if __name__ == '__main__':
  42. #
  43. # sched = BlockingScheduler()
  44. # sched.add_job(func_run, 'cron', hour=0, minute=0,
  45. # second=30)
  46. # sched.start()