import time import warnings warnings.filterwarnings('ignore') from apscheduler.schedulers.blocking import BlockingScheduler from sync_amz_data.settings import MYSQL_AUTH_CONF, MYSQL_DATA_CONF 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: 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) sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT",days=days,**{"level":"SKU"}) time.sleep(3.5) sp_api_client.SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT",days=days,**{"level":"PARENT"}) time.sleep(3.5) except Exception as e: print(e) func_run() # if __name__ == '__main__': # # sched = BlockingScheduler() # sched.add_job(func_run, 'cron', hour=0, minute=0, # second=30) # sched.start()