-
Notifications
You must be signed in to change notification settings - Fork 1
/
recommend.py
executable file
·74 lines (64 loc) · 2.35 KB
/
recommend.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
#!/usr/bin/env python
import csv, sys, cgitb, os, cgi
from deck_mysql import DeckDB
from printers import TextOutput, HTMLOutput
from login import check_login
output = None
def recommend_checks(tournament, form):
try:
with DeckDB() as db:
id = db.getEventId(tournament)
targetTables = db.get_recommendations(id, n=6, rand=False)
randomTables = db.get_recommendations(id, n=4, rand=True)
maxrounds = db.get_round(id)
headers = output.getHeaders(maxrounds)
for (tables, name) in [(targetTables, "Tables live for Top 8"), (randomTables, "Random Tables")]:
output.heading(name)
for (tablenumber, player1, player2) in tables:
output.heading("Table %s"%tablenumber)
if db.isEventTeam(tournament):
output.createButton(form, "deckcheck", {"table":tablenumber, 'seat':'0'}, "Checked Seat A this round")
output.createButton(form, "deckcheck", {"table":tablenumber, 'seat':'1'}, "Checked Seat B this round")
output.createButton(form, "deckcheck", {"table":tablenumber, 'seat':'2'}, "Checked Seat C this round")
else:
output.createButton(form, "deckcheck", {"table":tablenumber}, "Checked this round")
with output.table(*headers):
output.printPlayer(player1, db, id, form)
output.printPlayer(player2, db, id, form)
except Exception as e:
output.printMessage("Failed to print recommendations: %s" % (e))
def docgi():
print """Content-type: text/html
<html>
<head><title>Deck Checks - recommend checks</title><link rel='stylesheet' href='style.css' /></head>
<body>
<h1>Recommended Checks</h1>
"""
form = cgi.FieldStorage()
with DeckDB() as db:
db.checkEvent(form["event"].value, output)
roundnum = db.get_round(db.getEventId(form["event"].value))
output.pageHeader(db, form['event'].value, roundnum, form)
if not check_login(output, form['event'].value, form['password'].value if 'password' in form else '', 'recommend'):
return
recommend_checks(form["event"].value, form)
output.printLink(form, 'root', 'Return to menu')
print """
</body>
</html>
"""
def main(args):
with DeckDB() as db:
db.checkEvent(args[0], output)
recommend_checks(args[0], {})
if __name__ == "__main__":
if 'REQUEST_URI' in os.environ:
cgitb.enable()
output = HTMLOutput()
docgi()
else:
if len(sys.argv) < 2:
print "Usage: recommend.py <event>"
sys.exit(1)
output = TextOutput()
main(sys.argv[1:])