# date_list = [i for i in list(pd.date_range('20180921','20190101'))] # conn = get_mysql_conn('db_zdt','local') # cursor = conn.cursor() # for d in date_list: # x=datetime.datetime.strftime(d, '%Y%m%d') # y=datetime.datetime.strftime(d, '%Y-%m-%d') # if ts.is_holiday(y): # continue # print(y) # check_cmd ='select 1 from `{}zdt`'.format(x) # try: # cursor.execute(check_cmd) # except Exception as e: # print(e) # obj = GetZDT(x) # obj.storedata() # else: # ret = cursor.fetchone() # print(ret) # continue check = False if check and is_holiday(): logger.info('Holiday') exit() logger.info("start") obj = GetZDT('20200731') obj.storedata()
print(e) engine = self.DB.get_engine('db_daily', 'qq') try: self.df_today_all.to_sql(self.today, engine) except Exception as e: print(e) pass def save_to_excel(self, df, filename, encoding='gbk'): try: df.to_csv('temp.csv', encoding=encoding, index=False) df = pd.read_csv('temp.csv', encoding=encoding, dtype={'code': str}) df.to_excel(filename, encoding=encoding) return True except Exception as e: print("Save to excel faile") print(e) return None if __name__ == "__main__": if is_holiday(): logger.info("Holidy") exit() logger.info("Start") obj = FetchDaily() obj.store()
def check_holiday(self): if is_holiday(): logger.info("Holidy") exit(0) else: logger.info("Start")