Mercurial > hg > rlgallery-misc
annotate web/archive.cgi @ 82:14850d283b54
Update information about ttyrec terminal size.
author | John "Elwin" Edwards |
---|---|
date | Wed, 07 Feb 2018 20:54:48 -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' |