I have to run a code which updates the details about 5 tables(table name, date, number of observations in the table on that date). The number of entries for these tables(A,B,C,D,E) are updated on a daily basis. The agenda is to create a history table which holds records date wise for all the tables. I made the code and need to apply the scheduler so that the code runs every 24 hrs. The problem is that I want to put only certain part of my code in scheduler and not the complete code. How do I do it ?
History table which will only run at the start of the process
data = [('A',len(A),t),('B',len(B),t),('C',len(C),t),('D',len(D),t),('E',len(E),t)] df = pd.DataFrame(data,columns=['Name','LENGTH','date']) df
This code will run everyday and will merge with the history table
import sched import time
scheduler = sched.scheduler(time.time, time.sleep)
def auto_table():
import datetime t= datetime.date.today()-datetime.timedelta(days=0) t data = [['A',len(A),t],['B',len(B),t],['C',len(C),t],['D',len(D),t], ['E',len(E),t]] df1 = pd.DataFrame(data,columns=['Name','LENGTH','date']) global df df=df.merge(df1,how='outer') return df print ('START:', time.time()) scheduler.enter(1, 1, auto_table())
scheduler.run()
##I got this error START: 1547819432.8968043
TypeError Traceback (most recent call last) in () 22 scheduler.enter(1, 1, auto_table()) 23 ---> 24 scheduler.run()
C:\ProgramData\Anaconda3\lib\sched.py in run(self, blocking) 152 delayfunc(time - now) 153 else: --> 154 action(*argument, **kwargs) 155 delayfunc(0) # Let other threads run 156
TypeError: 'DataFrame' object is not callable