-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
61 lines (50 loc) · 1.73 KB
/
main.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
57
58
59
60
import os
import logging
import yaml
import refresh
import model
import orm
import csdc
import web
import time
import datetime
import postquell
SOURCES_DIR = './sources'
CONFIG_FILE = 'config.yml'
if not os.path.isfile(CONFIG_FILE):
CONFIG_FILE = 'config_default.yml'
CONFIG = yaml.safe_load(open(CONFIG_FILE, encoding='utf8'))
logging_level = logging.NOTSET
if 'logging level' in CONFIG and hasattr(logging, CONFIG['logging level']):
logging_level = getattr(logging, CONFIG['logging level'])
logging.basicConfig(level=logging_level)
#logging.getLogger('sqlalchemy.engine').setLevel(logging_level)
if __name__=='__main__':
orm.initialize(CONFIG['db uri'])
model.setup_database()
refresh.refresh(CONFIG['sources file'], SOURCES_DIR)
csdc.initialize_weeks()
t_i = time.time()
now = datetime.datetime.now(datetime.timezone.utc)
oldmask = os.umask(18)
for wk in csdc.weeks:
if wk.start > now:
continue
scorepage = os.path.join(CONFIG['www dir'],"{}.html".format(wk.number))
with open(scorepage, 'w') as f:
f.write(web.scorepage(wk))
logging.info("Rebuilt score pages in {} seconds.".format(time.time() -
t_i))
standings = os.path.join(CONFIG['www dir'],"standings.html")
with open(standings, 'w') as f:
f.write(web.standingspage())
index = os.path.join(CONFIG['www dir'],"index.html")
with open(index, 'w') as f:
f.write(web.overviewpage())
rules = os.path.join(CONFIG['www dir'],"rules.html")
with open(rules, 'w') as f:
f.write(web.rulespage())
pqjson = os.path.join(CONFIG['www dir'],"postquell.json")
with open(pqjson, 'w') as f:
postquell.dumps(f, csdc.current_week())
os.umask(oldmask)