-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_scheduler.py
52 lines (46 loc) · 1.67 KB
/
task_scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from cmath import nan
import subprocess
from datetime import datetime
import pandas as pd
import time
import os
def run_file(title, path, file, time):
try:
filepath = (path+file)
print('Running the process, '+title+' at '+ str(time))
p = subprocess.Popen(filepath, shell=True)
stdout, stderr = p.communicate()
res = ('Process '+ title + ' was finished at '+str(time)+' STATUS: SUCCESS')
return res
except:
res = ('Process '+ title + ' was finished at '+str(time)+' STATUS: FAILED')
return res
def valida_exec(title,filepath,time,now_dt):
print('Valida Execução')
time_last_up = datetime.fromtimestamp(os.path.getmtime(filepath)).strftime("%d-%m-%Y")
if time_last_up < now_dt:
f = open("log.txt", "a")
f.write(now_dt + ' - '+ title + " - Falhou em atualizar.\n")
f.close()
else:
f = open("log.txt", "a")
f.write(now_dt + ' - '+ title + " - Atualizou com sucesso.\n")
f.close()
while True:
#csv structure needs to be at the sample
df = pd.read_csv('tasks.csv')
ls = df.values.tolist()
for i in ls:
now_dt = datetime.now().strftime("%d-%m-%Y")
now = datetime.now().strftime("%H:%M:%S")
weekday = datetime.today().strftime('%A')
if i[4] != weekday:
if i[3] == now:
exec = run_file(i[0],i[1],i[2],i[3])
time.sleep(60)
print(exec)
else:
if i[4] == weekday and i[3] == now:
exec = run_file(i[0],i[1],i[2],i[3])
time.sleep(60)
print(exec)