Mercurial > hg > rlgallery-misc
annotate web/archive.cgi @ 86:5f1b4d3151bb
Add some neglected dgamelaunch initialization commands.
author | John "Elwin" Edwards |
---|---|
date | Sat, 24 Nov 2018 10:34:26 -0500 |
parents | 6138c27d1950 |
children |
rev | line source |
---|---|
30 | 1 #!/usr/bin/python3 |
0
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 |
30 | 9 import pytz |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
10 import html |
33
25843238434a
Change the Python module's name back to rlgall.
John "Elwin" Edwards
parents:
30
diff
changeset
|
11 import rlgall |
6
4778ab7de7aa
web/archive.cgi: disable cgitb by default.
John "Elwin" Edwards <elwin@sdf.org>
parents:
5
diff
changeset
|
12 #import cgitb |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
13 |
6
4778ab7de7aa
web/archive.cgi: disable cgitb by default.
John "Elwin" Edwards <elwin@sdf.org>
parents:
5
diff
changeset
|
14 #cgitb.enable() |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
15 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
16 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
|
17 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
|
18 """ |
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 ttyrecbase = "/var/dgl/dgldir/ttyrec/" |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
21 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
22 def input_game(outf, selected=None): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
23 "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
|
24 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
|
25 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
|
26 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
|
27 for game in rlgall.gamelist: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
28 # 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
|
29 # into rlgall. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
30 if selected and selected == game.uname: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
31 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
|
32 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
33 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
|
34 outf.write('</select></div>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
35 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
36 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
37 def input_name(outf, defaultval=None): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
38 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
|
39 if defaultval: |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
40 outf.write(defstr.format(html.escape(defaultval))) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
41 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
42 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
|
43 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
44 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
45 def input_time(outf, defaultval=None): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
46 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
|
47 if defaultval: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
48 outf.write(defstr.format(defaultval)) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
49 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
50 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
|
51 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
52 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 sstr = '<div>Date: <select name="year">\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
59 # Default to today |
30 | 60 now = datetime.now(pytz.utc) |
5
a583700c0ca4
web/archive.cgi: fix backward comparisons.
John "Elwin" Edwards <elwin@sdf.org>
parents:
4
diff
changeset
|
61 if dvals[0] == None: |
4
f5a37cc7f41f
Continue removing the time module.
John "Elwin" Edwards <elwin@sdf.org>
parents:
3
diff
changeset
|
62 dvals[0] = now.year |
5
a583700c0ca4
web/archive.cgi: fix backward comparisons.
John "Elwin" Edwards <elwin@sdf.org>
parents:
4
diff
changeset
|
63 if dvals[1] == None: |
4
f5a37cc7f41f
Continue removing the time module.
John "Elwin" Edwards <elwin@sdf.org>
parents:
3
diff
changeset
|
64 dvals[1] = now.month |
5
a583700c0ca4
web/archive.cgi: fix backward comparisons.
John "Elwin" Edwards <elwin@sdf.org>
parents:
4
diff
changeset
|
65 if dvals[2] == None: |
4
f5a37cc7f41f
Continue removing the time module.
John "Elwin" Edwards <elwin@sdf.org>
parents:
3
diff
changeset
|
66 dvals[2] = now.day |
f5a37cc7f41f
Continue removing the time module.
John "Elwin" Edwards <elwin@sdf.org>
parents:
3
diff
changeset
|
67 for year in range(2010, now.year + 1): |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
68 if year == dvals[0]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
69 sstr += soptstr.format(year, year) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
70 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
71 sstr += optstr.format(year, year) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
72 sstr += '</select>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
73 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
74 sstr = '<select name="month">\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
75 for month in range(1, 13): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
76 if month == dvals[1]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
77 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
|
78 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
79 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
|
80 sstr += '</select>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
81 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
82 sstr = '<select name="day">\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
83 for day in range(1, 32): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
84 if day == dvals[2]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
85 sstr += soptstr.format(day, day) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
86 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
87 sstr += optstr.format(day, day) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
88 sstr += '</select></div>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
89 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
90 sstr = '<div>Approximate time: ' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
91 if dvals[3] != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
92 sstr += tf.format("hour", dvals[3]) |
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("hour") |
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[4] != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
97 sstr += tf.format("minute", dvals[4]) |
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("minute") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
100 sstr += " : " |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
101 if dvals[5] != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
102 sstr += tf.format("second", dvals[5]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
103 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
104 sstr += emptf.format("second") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
105 sstr += ' (optional)</div>\n' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
106 outf.write(sstr) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
107 return |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
108 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
109 def checkempty(cgidata): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
110 exkeys = set(cgidata.keys()) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
111 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
|
112 "minute", "second"]) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
113 return wanted.isdisjoint(exkeys) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
114 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
115 def processname(fdata, errlist): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
116 "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
|
117 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
|
118 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
|
119 if "name" not in fdata: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
120 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
|
121 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
122 # 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
|
123 # digging all over the filesystem. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
124 formname = fdata.getfirst("name").rpartition("/")[2] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
125 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
126 os.stat(ttyrecbase + formname) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
127 except OSError: |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
128 errlist.append(cantfind.format(html.escape(formname))) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
129 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
130 return formname |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
131 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
132 def processgame(fdata, errlist): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
133 "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
|
134 it asks for. Errors appended to errlist." |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
135 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
|
136 if "game" not in fdata: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
137 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
|
138 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
139 formgame = fdata.getfirst("game") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
140 for agame in rlgall.gamelist: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
141 if agame.uname == formgame: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
142 return agame |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
143 errlist.append(cantfind.format(html.escape(formgame))) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
144 return None |
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 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
|
147 "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
|
148 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
|
149 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
|
150 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
151 # 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
|
152 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
|
153 like {0}. Try the form instead.' |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
154 utime = None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
155 formtime = fdata.getfirst("time") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
156 if formtime: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
157 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
158 utime = int(formtime) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
159 except ValueError: |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
160 errlist.append(badtime.format(html.escape(formtime))) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
161 return None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
162 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
163 if utime < 0: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
164 utime = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
165 if utime != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
166 chtime = time.gmtime(utime) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
167 for i in range(6): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
168 hlist[i] = chtime[i] |
30 | 169 return datetime.fromtimestamp(utime, pytz.utc) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
170 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
171 # 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
|
172 lerrors = [] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
173 year = month = day = hour = minute = second = None |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
174 fyear = fdata.getfirst("year") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
175 if not fyear: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
176 lerrors.append("No year was provided.") |
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 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
179 year = int(fyear) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
180 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
181 lerrors.append("Invalid year.") |
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 if year < 2010: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
184 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
|
185 elif year > time.gmtime()[0]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
186 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
|
187 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
188 hlist[0] = year # It is valid |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
189 fmonth = fdata.getfirst("month") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
190 if not fmonth: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
191 lerrors.append("No month was provided.") |
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 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
194 month = int(fmonth) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
195 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
196 lerrors.append("Invalid month.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
197 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
198 if month < 1 or month > 12: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
199 lerrors.append("Invalid month.") |
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 hlist[1] = month |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
202 fday = fdata.getfirst("day") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
203 if not fday: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
204 lerrors.append("No day was provided.") |
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 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
207 day = int(fday) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
208 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
209 lerrors.append("Invalid day.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
210 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
211 if day < 1 or day > 31: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
212 lerrors.append("Invalid day.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
213 elif not lerrors: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
214 if day > calendar.monthrange(year, month)[1]: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
215 lerrors.append("Invalid day.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
216 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
217 hlist[2] = day |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
218 fhour = fdata.getfirst("hour") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
219 if not fhour: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
220 hour = 0 # Assume things. |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
221 hlist[3] = 0 |
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 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
224 hour = int(fhour) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
225 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
226 lerrors.append("Invalid hour.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
227 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
228 if hour < 0 or hour > 23: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
229 lerrors.append("Invalid hour.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
230 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
231 hlist[3] = hour |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
232 fminute = fdata.getfirst("minute") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
233 if not fminute: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
234 minute = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
235 hlist[4] = 0 |
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 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
238 minute = int(fminute) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
239 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
240 lerrors.append("Invalid minute.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
241 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
242 if minute < 0 or minute > 59: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
243 lerrors.append("Invalid minute.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
244 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
245 hlist[4] = minute |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
246 fsecond = fdata.getfirst("second") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
247 if not fsecond: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
248 second = 0 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
249 hlist[5] = 0 |
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 try: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
252 second = int(fsecond) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
253 except ValueError: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
254 lerrors.append("Invalid second.") |
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 if second < 0 or second > 59: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
257 lerrors.append("Invalid second.") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
258 if second == 60 or second == 61: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
259 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
|
260 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
261 hlist[5] = second |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
262 if lerrors: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
263 errlist.extend(lerrors) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
264 return None |
30 | 265 return datetime(year, month, day, hour, minute, second, 0, pytz.utc) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
266 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
267 # Begin processing |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
268 fdata = cgi.FieldStorage() |
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 # 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
|
271 # 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
|
272 isnotsearch = checkempty(fdata) |
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 errors = [] |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
275 formname = dungeon = searchtime = None |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
276 timepieces = [None, None, None, None, None, None] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
277 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
278 if not isnotsearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
279 formname = processname(fdata, errors) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
280 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
|
281 searchtime = processtime(fdata, errors, timepieces) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
282 |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
283 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
|
284 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
285 # 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
|
286 gamefiles = [] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
287 if dosearch: |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 conn = rlgall.getconn() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
292 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
|
293 cur.execute(query1, [formname, searchtime, searchtime]) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
294 result = cur.fetchone() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
295 if result: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
296 gamefiles = result[0] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
297 else: |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
298 cur.execute(query2, [formname, searchtime]) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
299 result = cur.fetchone() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
300 if result: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
301 gamefiles = result[0] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
302 else: |
2
8f49df4074d7
Convert web/archive.cgi to use the new SQL timestamps.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
303 cur.execute(query3, [formname, searchtime]) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
304 result = cur.fetchone() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
305 if result: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
306 gamefiles = result[0] |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
307 cur.close() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
308 conn.close() |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
309 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
310 # Now we are ready to print the page. |
30 | 311 sys.stdout.write("Content-Type: text/html; charset=utf-8\r\n\r\n") |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
312 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
313 sys.stdout.write(rlgall.phead.format("Archive")) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
314 sys.stdout.write(rlgall.ptop) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
315 sys.stdout.write(rlgall.navtop.format("Archive")) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
316 sys.stdout.write('<div class="content">\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
317 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
|
318 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
319 if dosearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 if not gamefiles: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
324 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
|
325 elif len(gamefiles) == 1: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
326 sys.stdout.write('<p><a href="/ttyrecs/{0}/{1}/{2}">1 ttyrec found.</a>\ |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
327 </p>\n'.format(html.escape(formname), dungeon.uname, gamefiles[0])) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
328 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
329 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
|
330 sys.stdout.write('<ul>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
331 for i, afile in enumerate(gamefiles): |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
332 sys.stdout.write('<li><a href="/ttyrecs/{0}/{1}/{2}">Section {3}</a>\ |
49
6138c27d1950
Escape the player's name when printing it into HTML.
John "Elwin" Edwards
parents:
34
diff
changeset
|
333 </li>\n'.format(html.escape(formname), dungeon.uname, afile, i + 1)) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
334 sys.stdout.write('</ul>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
335 if isnotsearch: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
336 sys.stdout.write(infop) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
337 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
338 # 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
|
339 sys.stdout.write('<p>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
340 for errmsg in errors: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
341 sys.stdout.write(errmsg + " ") |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
342 sys.stdout.write('</p>\n') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
343 # 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
|
344 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
|
345 if dungeon != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
346 input_game(sys.stdout, dungeon.uname) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
347 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
348 input_game(sys.stdout) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
349 if formname != None: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
350 input_name(sys.stdout, formname) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
351 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
352 input_name(sys.stdout) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
353 input_datetime(sys.stdout, timepieces) |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
354 if dosearch: |
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 Again"></div></form>') |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
356 else: |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
357 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
|
358 |
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
359 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
|
360 sys.stdout.write('<p><a href="/about/ttyrec.html">What are ttyrecs?</a></p>') |
34
86b616d88020
Add a footer with some links to the Web pages.
John "Elwin" Edwards
parents:
33
diff
changeset
|
361 sys.stdout.write('</div>\n') |
86b616d88020
Add a footer with some links to the Web pages.
John "Elwin" Edwards
parents:
33
diff
changeset
|
362 sys.stdout.write(rlgall.pend) |
0
5ba2123d2c20
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
363 exit() |