forked from crawl/dcss_tourney
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_page.py
94 lines (80 loc) · 2.54 KB
/
update_page.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
import mako.template
import mako.lookup
import os
import os.path
import loaddb
import query
import crawl_utils
from logging import debug, info, warn, error
TEMPLATE_DIR = os.path.abspath('templates')
MAKO_LOOKUP = mako.lookup.TemplateLookup(directories = [ TEMPLATE_DIR ])
def render(c, page, dest=None, pars=None):
"""Given a db context and a .mako template (without the .mako extension)
renders the template and writes it back to <page>.html in the tourney
scoring directory. Setting dest overrides the destination filename."""
target = "%s/%s.html" % (crawl_utils.SCORE_FILE_DIR, dest or page)
t = MAKO_LOOKUP.get_template(page + '.mako')
try:
f = open(target, 'w')
pars = pars or { }
pars['cursor'] = c
try:
f.write( t.render( attributes = pars ) )
finally:
f.close()
except Exception, e:
warn("Error generating page %s: %s" % (page, e))
raise
# Don't rethrow.
def tourney_overview(c):
info("Updating overview page")
render(c, 'overview')
def player_pages(c):
info("Updating all player pages")
render(c, 'species-classes')
render(c, 'banners')
render(c, 'all-players')
render(c, 'wins-and-kills')
render(c, 'current-games')
render(c, 'combo-scoreboard')
render(c, 'combo-leaders')
render(c, 'killers')
render(c, 'gkills')
for p in query.get_players(c):
player_page(c, p)
def index_page(c):
info("Updating index page")
render(c, 'index')
render(c, 'unique-list')
def team_page(c, captain):
info("Updating team page for captain %s" % captain)
render(c, 'clan', dest = ('%s/%s' % (crawl_utils.CLAN_BASE, captain.lower())),
pars = { 'captain' : captain })
def team_pages(c):
info("Updating teams page")
render(c, 'teams')
for captain in query.get_team_captains(c):
team_page(c, captain)
def player_page(c, player):
info("Updating player page for %s" % player)
render(c, 'player',
dest = ('%s/%s' % (crawl_utils.PLAYER_BASE, player.lower())),
pars = { 'player' : player })
# Update tourney overview every 5 mins.
INTERVAL = crawl_utils.UPDATE_INTERVAL
TIMER = [ loaddb.define_timer( INTERVAL, tourney_overview ),
loaddb.define_timer( INTERVAL, team_pages ),
loaddb.define_timer( INTERVAL, player_pages )
]
LISTENER = [ loaddb.define_cleanup(tourney_overview),
loaddb.define_cleanup(team_pages),
loaddb.define_cleanup(player_pages)
]
if __name__ == '__main__':
db = loaddb.connect_db()
try:
for l in LISTENER:
l.cleanup(db)
finally:
db.close()