forked from rspeer/dominionstats
-
Notifications
You must be signed in to change notification settings - Fork 17
/
update_loop.py
42 lines (35 loc) · 1.14 KB
/
update_loop.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
import os
import time
from datetime import date, timedelta
import utils
import sys
utils.ensure_exists('static/status')
cmds = [
'python scrape.py',
'python parse_game.py',
'python load_parsed_data.py ',
'python analyze.py',
'python goals.py',
'python count_buys.py',
'python run_trueskill.py',
'python optimal_card_ratios.py',
'python goal_stats.py',
'python scrape_leaderboard.py',
'python load_leaderboard.py',
]
extra_args = sys.argv[1:]
# should think about how to parrallelize this for multiprocessor machines.
while True:
for cmd in cmds:
month_ago = (date.today() - timedelta(days=30)).strftime('%Y%m%d')
fmt_dict = {'month_ago': month_ago}
cmd = (cmd % fmt_dict)
status_fn = (cmd.replace(' ', '_') + '-' +
date.today().isoformat() + '-' +
time.strftime('%H:%M:%S') + '.txt')
cmd = cmd + ' ' + ' '.join(extra_args) + ' 2>&1 | tee -a ' + status_fn
print cmd
os.system(cmd)
os.system('mv %s static/status' % status_fn)
print 'sleeping'
time.sleep(60*15) # try to update every 15 mins