Mercurial > hg > rlgallery-misc
annotate web/archive.cgi @ 41:d3ccdc195796
rlgall.py: delete a few lines that got moved elsewhere
| author | John "Elwin" Edwards | 
|---|---|
| date | Fri, 10 Jan 2014 17:01:11 -0500 | 
| parents | 86b616d88020 | 
| children | 6138c27d1950 | 
| 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: 
0diff
changeset | 8 from datetime import datetime | 
| 30 | 9 import pytz | 
| 33 
25843238434a
Change the Python module's name back to rlgall.
 John "Elwin" Edwards parents: 
30diff
changeset | 10 import rlgall | 
| 6 
4778ab7de7aa
web/archive.cgi: disable cgitb by default.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
5diff
changeset | 11 #import cgitb | 
| 0 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 12 | 
| 6 
4778ab7de7aa
web/archive.cgi: disable cgitb by default.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
5diff
changeset | 13 #cgitb.enable() | 
| 0 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 14 | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 15 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 | 16 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 | 17 """ | 
| 
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 ttyrecbase = "/var/dgl/dgldir/ttyrec/" | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 20 | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 21 def input_game(outf, selected=None): | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 22 "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 | 23 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 | 24 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 | 25 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 | 26 for game in rlgall.gamelist: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 27 # 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 | 28 # into rlgall. | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 29 if selected and selected == game.uname: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 30 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 | 31 else: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 32 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 | 33 outf.write('</select></div>\n') | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 34 return | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 35 | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 36 def input_name(outf, defaultval=None): | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 37 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 | 38 if defaultval: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 39 outf.write(defstr.format(defaultval)) | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 40 else: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 41 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 | 42 return | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 43 | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 44 def input_time(outf, defaultval=None): | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 45 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 | 46 if defaultval: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 47 outf.write(defstr.format(defaultval)) | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 48 else: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 49 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 | 50 return | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 51 | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 52 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 | 53 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 | 54 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 | 55 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 | 56 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 | 57 sstr = '<div>Date: <select name="year">\n' | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 58 # Default to today | 
| 30 | 59 now = datetime.now(pytz.utc) | 
| 5 
a583700c0ca4
web/archive.cgi: fix backward comparisons.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
4diff
changeset | 60 if dvals[0] == None: | 
| 4 
f5a37cc7f41f
Continue removing the time module.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
3diff
changeset | 61 dvals[0] = now.year | 
| 5 
a583700c0ca4
web/archive.cgi: fix backward comparisons.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
4diff
changeset | 62 if dvals[1] == None: | 
| 4 
f5a37cc7f41f
Continue removing the time module.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
3diff
changeset | 63 dvals[1] = now.month | 
| 5 
a583700c0ca4
web/archive.cgi: fix backward comparisons.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
4diff
changeset | 64 if dvals[2] == None: | 
| 4 
f5a37cc7f41f
Continue removing the time module.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
3diff
changeset | 65 dvals[2] = now.day | 
| 
f5a37cc7f41f
Continue removing the time module.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
3diff
changeset | 66 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 | 67 if year == dvals[0]: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 68 sstr += soptstr.format(year, year) | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 69 else: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 70 sstr += optstr.format(year, year) | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 71 sstr += '</select>\n' | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 72 outf.write(sstr) | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 73 sstr = '<select name="month">\n' | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 74 for month in range(1, 13): | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 75 if month == dvals[1]: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 76 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 | 77 else: | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 78 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 | 79 sstr += '</select>\n' | 
| 
5ba2123d2c20
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 80 outf.write(sstr) | 
