-
Notifications
You must be signed in to change notification settings - Fork 1
/
export.py
executable file
·52 lines (46 loc) · 1.41 KB
/
export.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
#!/usr/bin/env python
import csv, sys, cgitb, os, cgi
from deck_mysql import DeckDB
from printers import TSVOutput, TextOutput
import top_tables, allchecks, pairings
def docgi():
print """Content-type: text/tab-separated-values
Content-disposition: attachment; filename=data.tsv
"""
form = cgi.FieldStorage()
with DeckDB() as db:
db.checkEvent(form["event"].value, TextOutput())
if 'type' in form and form['type']:
if "top" == form['type'].value:
top_tables.output = TSVOutput()
top_tables.top_tables(form["event"].value, {})
elif "checks" == form['type'].value:
allchecks.output = TSVOutput()
allchecks.allchecks(form["event"].value, {})
elif "pairings" == form['type'].value:
pairings.output = TSVOutput()
pairings.pairings(form["event"].value, int(form['round'].value) if 'round' in form else None)
else:
print "ERROR: type must be top, pairings or checks"
else:
print "ERROR: must specify type"
def main(args):
with DeckDB() as db:
db.checkEvent(args[1], TextOutput())
if "top" == args[0]:
top_tables.output = TSVOutput()
top_tables.top_tables(args[1])
elif "checks" == args[0]:
allchecks.output = TSVOutput()
allchecks.allchecks(args[1])
else:
print "Type must be top or checks";
if __name__ == "__main__":
if 'REQUEST_URI' in os.environ:
cgitb.enable()
docgi()
else:
if len(sys.argv) < 3:
print "Usage: export.py <type> <event>"
sys.exit(1)
main(sys.argv[1:])