-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
56 lines (47 loc) · 1.53 KB
/
deploy.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
53
54
55
56
import os
import subprocess
import time
import traceback
from alerts import post_alerts
from helpers import STATIC_DIR, get_confirmed, get_cur_time, format_time
from pleth import write_plot
from download import download_and_write_historical
def run_git(*commands, files=[]):
assert all([isinstance(command, str) for command in commands])
final = ['git'] + list(commands) + list(files)
output = subprocess.check_output(final)
if output:
print(output)
def get_static_filenames():
files = []
for filename in os.listdir(STATIC_DIR):
if filename.startswith('.'):
continue
filepath = os.path.join(STATIC_DIR, filename)
if os.path.isfile(filepath):
files.append(filepath)
return files
if __name__ == '__main__':
prev_label = get_confirmed()
while True:
try:
files = get_static_filenames()
files.append('data.csv')
run_git('checkout', files=files)
run_git('pull')
label = write_plot()
if label != prev_label:
try:
download_and_write_historical()
post_alerts()
except:
traceback.print_exc()
run_git('add', files=files)
run_git('commit','-m', 'Data update', files=files)
run_git('push')
prev_label = label
except:
traceback.print_exc()
print(format_time(get_cur_time()))
print()
time.sleep(3901)