Mercurial > hg > rlgallery-misc
annotate web/archive.cgi @ 3:a943cfdfbad9
Remove obsolete code.
Remove some unnecessary module imports and code that worked with UNIX
timestamps.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Thu, 26 Jul 2012 09:35:07 -0700 |
parents | 8f49df4074d7 |
children | f5a37cc7f41f |
rev | line source |
---|---|
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
2 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
3 import cgi |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
4 import os |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
5 import sys |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
6 import time |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
7 import calendar |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
8 from datetime import datetime |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
9 import rlgalldb as rlgall |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
10 import cgitb |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
11 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
12 cgitb.enable() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
13 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
14 infop = """<p>Looking for ttyrec files? Don't like digging through Web directory listings, converting time zones in your head, or guessing how many files |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
15 the game was spread across? The Archivist can find them all for you.</p> |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
16 """ |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
17 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
18 ttyrecbase = "/var/dgl/dgldir/ttyrec/" |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
19 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
20 def input_game(outf, selected=None): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
21 "Prints the form components for selecting a game." |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
22 selstr = '<option label="{0}" value="{1}" selected="selected">{0}</option>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
23 unselstr = '<option label="{0}" value="{1}">{0}</option>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
24 outf.write('<div>Dungeon name: <select name="game">\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
25 for game in rlgall.gamelist: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
26 # This will cause trouble if someone puts games with identical names |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
27 # into rlgall. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
28 if selected and selected == game.uname: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
29 outf.write(selstr.format(game.name, game.uname)) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
30 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
31 outf.write(unselstr.format(game.name, game.uname)) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
32 outf.write('</select></div>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
33 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
34 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
35 def input_name(outf, defaultval=None): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
36 defstr = '<div>Adventurer\'s name: <input type="text" name="name" value="{0}"></div>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
37 if defaultval: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
38 outf.write(defstr.format(defaultval)) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
39 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
40 outf.write('<div>Adventurer\'s Name: <input type="text" name="name"></div>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
41 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
42 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
43 def input_time(outf, defaultval=None): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
44 defstr = '<div>Time: <input type="text" name="time" value="{0}"></div>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
45 if defaultval: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
46 outf.write(defstr.format(defaultval)) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
47 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
48 outf.write('<div>Time: <input type="text" name="time"></div>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
49 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
50 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
51 def input_datetime(outf, dvals=[None, None, None, None, None, None]): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
52 optstr = '<option value="{0}" label="{1}">{1}</option>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
53 soptstr = '<option value="{0}" label="{1}" selected="selected">{1}</option>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
54 tf = '<input type="text" size="2" maxlength="2" name="{0}" value="{1:02}">' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
55 emptf = '<input type="text" size="2" maxlength="2" name="{0}">' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
56 sstr = '<div>Date: <select name="year">\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
57 # Default to today |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
58 now = time.gmtime() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
59 for dindex in range(3): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
60 if not dvals[dindex]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
61 dvals[dindex] = now[dindex] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
62 for year in range(2010, now[0] + 1): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
63 if year == dvals[0]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
64 sstr += soptstr.format(year, year) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
65 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
66 sstr += optstr.format(year, year) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
67 sstr += '</select>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
68 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
69 sstr = '<select name="month">\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
70 for month in range(1, 13): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
71 if month == dvals[1]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
72 sstr += soptstr.format(month, calendar.month_name[month]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
73 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
74 sstr += optstr.format(month, calendar.month_name[month]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
75 sstr += '</select>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
76 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
77 sstr = '<select name="day">\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
78 for day in range(1, 32): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
79 if day == dvals[2]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
80 sstr += soptstr.format(day, day) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
81 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
82 sstr += optstr.format(day, day) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
83 sstr += '</select></div>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
84 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
85 sstr = '<div>Approximate time: ' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
86 if dvals[3] != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
87 sstr += tf.format("hour", dvals[3]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
88 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
89 sstr += emptf.format("hour") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
90 sstr += " : " |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
91 if dvals[4] != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
92 sstr += tf.format("minute", dvals[4]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
93 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
94 sstr += emptf.format("minute") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
95 sstr += " : " |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
96 if dvals[5] != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
97 sstr += tf.format("second", dvals[5]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
98 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
99 sstr += emptf.format("second") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
100 sstr += ' (optional)</div>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
101 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
102 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
103 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
104 def checkempty(cgidata): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
105 exkeys = set(cgidata.keys()) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
106 wanted = set(["name", "game", "time", "year", "month", "day", "hour", |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
107 "minute", "second"]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
108 return wanted.isdisjoint(exkeys) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
109 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
110 def processname(fdata, errlist): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
111 "Takes a CGI data object, extracts the player name, checks its validity, \ |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
112 and returns it. If errors are encountered, they are appended to errlist." |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
113 cantfind = "I have no record of an adventurer called {0}." |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
114 if "name" not in fdata: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
115 errlist.append("You didn\'t tell me the adventurer\'s name.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
116 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
117 # Just in case someone supplies something nasty, make sure they can't go |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
118 # digging all over the filesystem. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
119 formname = fdata.getfirst("name").rpartition("/")[2] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
120 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
121 os.stat(ttyrecbase + formname) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
122 except OSError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
123 errlist.append(cantfind.format(cgi.escape(formname))) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
124 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
125 return formname |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
126 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
127 def processgame(fdata, errlist): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
128 "Takes a CGI data object and returns the game from rlgall.gamelist that \ |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
129 it asks for. Errors appended to errlist." |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
130 cantfind = "I've never heard of a dungeon called {0}." |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
131 if "game" not in fdata: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
132 errlist.append('You didn\'t choose a dungeon.') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
133 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
134 formgame = fdata.getfirst("game") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
135 for agame in rlgall.gamelist: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
136 if agame.uname == formgame: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
137 return agame |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
138 errlist.append(cantfind.format(cgi.escape(formgame))) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
139 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
140 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
141 def processtime(fdata, errlist, hlist): |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
142 "Takes a CGI data object and converts to a datetime object by finding \ |
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
143 fields called year, month, etc. Any errors get appended to errlist. \ |
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
144 hlist should contain 6 components, for ymd-hms fields." |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
145 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
146 # Timestamp overrides human-readable, even if it's invalid. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
147 badtime = 'The time field is for Unix clocks, which never say anything \ |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
148 like {0}. Try the form instead.' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
149 utime = None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
150 formtime = fdata.getfirst("time") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
151 if formtime: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
152 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
153 utime = int(formtime) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
154 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
155 errlist.append(badtime.format(cgi.escape(formtime))) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
156 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
157 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
158 if utime < 0: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
159 utime = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
160 if utime != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
161 chtime = time.gmtime(utime) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
162 for i in range(6): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
163 hlist[i] = chtime[i] |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
164 return datetime.fromtimestamp(utime, rlgall.utc) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
165 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
166 # Now try to get a human-readable specification. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
167 lerrors = [] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
168 year = month = day = hour = minute = second = None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
169 fyear = fdata.getfirst("year") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
170 if not fyear: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
171 lerrors.append("No year was provided.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
172 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
173 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
174 year = int(fyear) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
175 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
176 lerrors.append("Invalid year.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
177 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
178 if year < 2010: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
179 lerrors.append("The Gallery has only existed since 2010.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
180 elif year > time.gmtime()[0]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
181 lerrors.append("I can't see into the future.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
182 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
183 hlist[0] = year # It is valid |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
184 fmonth = fdata.getfirst("month") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
185 if not fmonth: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
186 lerrors.append("No month was provided.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
187 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
188 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
189 month = int(fmonth) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
190 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
191 lerrors.append("Invalid month.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
192 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
193 if month < 1 or month > 12: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
194 lerrors.append("Invalid month.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
195 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
196 hlist[1] = month |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
197 fday = fdata.getfirst("day") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
198 if not fday: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
199 lerrors.append("No day was provided.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
200 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
201 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
202 day = int(fday) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
203 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
204 lerrors.append("Invalid day.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
205 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
206 if day < 1 or day > 31: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
207 lerrors.append("Invalid day.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
208 elif not lerrors: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
209 if day > calendar.monthrange(year, month)[1]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
210 lerrors.append("Invalid day.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
211 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
212 hlist[2] = day |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
213 fhour = fdata.getfirst("hour") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
214 if not fhour: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
215 hour = 0 # Assume things. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
216 hlist[3] = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
217 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
218 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
219 hour = int(fhour) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
220 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
221 lerrors.append("Invalid hour.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
222 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
223 if hour < 0 or hour > 23: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
224 lerrors.append("Invalid hour.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
225 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
226 hlist[3] = hour |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
227 fminute = fdata.getfirst("minute") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
228 if not fminute: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
229 minute = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
230 hlist[4] = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
231 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
232 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
233 minute = int(fminute) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
234 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
235 lerrors.append("Invalid minute.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
236 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
237 if minute < 0 or minute > 59: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
238 lerrors.append("Invalid minute.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
239 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
240 hlist[4] = minute |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
241 fsecond = fdata.getfirst("second") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
242 if not fsecond: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
243 second = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
244 hlist[5] = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
245 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
246 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
247 second = int(fsecond) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
248 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
249 lerrors.append("Invalid second.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
250 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
251 if second < 0 or second > 59: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
252 lerrors.append("Invalid second.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
253 if second == 60 or second == 61: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
254 lerrors.append("Leap seconds are worse than purple worms.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
255 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
256 hlist[5] = second |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
257 if lerrors: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
258 errlist.extend(lerrors) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
259 return None |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
260 #return calendar.timegm([year, month, day, hour, minute, second, 0, 0, 0]) |
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
261 return datetime(year, month, day, hour, minute, second, 0, rlgall.utc) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
262 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
263 # Begin processing |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
264 fdata = cgi.FieldStorage() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
265 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
266 # If this is true, the user didn't supply any search criteria, so assume it |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
267 # doesn't want a search. Otherwise, every error or omission must be printed. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
268 isnotsearch = checkempty(fdata) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
269 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
270 errors = [] |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
271 formname = dungeon = searchtime = None |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
272 timepieces = [None, None, None, None, None, None] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
273 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
274 if not isnotsearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
275 formname = processname(fdata, errors) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
276 dungeon = processgame(fdata, errors) |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
277 searchtime = processtime(fdata, errors, timepieces) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
278 |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
279 dosearch = formname != None and dungeon != None and searchtime != None |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
280 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
281 # Find the actual files, and put them in a list called gamefiles. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
282 gtimes = [0, int(time.time())] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
283 relgame = None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
284 gamefiles = [] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
285 if dosearch: |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
286 query1 = "SELECT ttyrecs FROM {0} WHERE name = %s AND startt <= %s AND endt >= %s;".format(dungeon.uname) |
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
287 query2 = "SELECT ttyrecs FROM {0} WHERE name = %s AND endt >= %s ORDER BY endt LIMIT 1;".format(dungeon.uname) |
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
288 query3 = "SELECT ttyrecs FROM {0} WHERE name = %s AND startt <= %s ORDER BY startt DESC LIMIT 1;".format(dungeon.uname) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
289 conn = rlgall.getconn() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
290 cur = conn.cursor() |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
291 cur.execute(query1, [formname, searchtime, searchtime]) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
292 result = cur.fetchone() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
293 if result: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
294 gamefiles = result[0] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
295 else: |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
296 cur.execute(query2, [formname, searchtime]) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
297 result = cur.fetchone() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
298 if result: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
299 gamefiles = result[0] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
300 else: |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
301 cur.execute(query3, [formname, searchtime]) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
302 result = cur.fetchone() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
303 if result: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
304 gamefiles = result[0] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
305 cur.close() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
306 conn.close() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
307 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
308 # Now we are ready to print the page. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
309 sys.stdout.write("Content-type: text/html\r\n\r\n") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
310 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
311 sys.stdout.write(rlgall.phead.format("Archive")) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
312 sys.stdout.write(rlgall.ptop) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
313 sys.stdout.write(rlgall.navtop.format("Archive")) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
314 sys.stdout.write('<div class="content">\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
315 sys.stdout.write(rlgall.pti.format("Guild Archives")) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
316 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
317 if dosearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
318 sys.stdout.write("<p>Expedition by {0} to {1} about {2}:</p>\n".format( |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
319 rlgall.playerlink(formname), dungeon.name, |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
320 searchtime.strftime("%Y/%m/%d %H:%M:%S"))) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
321 if not gamefiles: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
322 sys.stdout.write("<p>No record found.</p>\n") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
323 elif len(gamefiles) == 1: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
324 sys.stdout.write('<p><a href="/ttyrecs/{0}/{1}/{2}">1 ttyrec found.</a>\ |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
325 </p>\n'.format(formname, dungeon.uname, gamefiles[0])) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
326 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
327 sys.stdout.write('<p>{0}-part ttyrec found.</p>\n'.format(len(gamefiles))) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
328 sys.stdout.write('<ul>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
329 for i, afile in enumerate(gamefiles): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
330 sys.stdout.write('<li><a href="/ttyrecs/{0}/{1}/{2}">Section {3}</a>\ |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
331 </li>\n'.format(formname, dungeon.uname, afile, i + 1)) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
332 sys.stdout.write('</ul>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
333 if isnotsearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
334 sys.stdout.write(infop) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
335 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
336 # There was information, but not good enough, i.e. errors. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
337 sys.stdout.write('<p>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
338 for errmsg in errors: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
339 sys.stdout.write(errmsg + " ") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
340 sys.stdout.write('</p>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
341 # Print out a search form, whether a search was done or not. |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
342 sys.stdout.write('<form action="/archive.cgi" method="get">\n') |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
343 if dungeon != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
344 input_game(sys.stdout, dungeon.uname) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
345 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
346 input_game(sys.stdout) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
347 if formname != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
348 input_name(sys.stdout, formname) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
349 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
350 input_name(sys.stdout) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
351 input_datetime(sys.stdout, timepieces) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
352 if dosearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
353 sys.stdout.write('<div><input type="submit" value="Search Again"></div></form>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
354 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
355 sys.stdout.write('<div><input type="submit" value="Search the Archive"></div></form>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
356 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
357 sys.stdout.write('<p>Or <a href="/ttyrecs/">browse all ttyrecs</a>.</p>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
358 sys.stdout.write('<p><a href="/about/ttyrec.html">What are ttyrecs?</a></p>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
359 sys.stdout.write("</div>\n</body>\n</html>\n") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
360 exit() |