comparison web/archive.cgi @ 0:5ba2123d2c20

Put this project under version control, finally. Scripts for rlgallery.org, using a PostgreSQL backend. The recorder system is in py/, CGI scripts are in web/.
author John "Elwin" Edwards <elwin@sdf.org>
date Wed, 25 Jul 2012 21:59:42 -0700
parents
children 8f49df4074d7
comparison
equal deleted inserted replaced
-1:000000000000 0:5ba2123d2c20
1 #!/usr/bin/python
2
3 import cgi
4 import os
5 import sys
6 import re
7 import time
8 import calendar
9 import rlgalldb as rlgall
10 import cgitb
11
12 cgitb.enable()
13
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
15 the game was spread across? The Archivist can find them all for you.</p>
16 """
17
18 ttyrecbase = "/var/dgl/dgldir/ttyrec/"
19 recre = r"(\d{4,4})-(\d{2,2})-(\d{2,2})\.(\d{2,2}):(\d{2,2}):(\d{2,2})\.ttyrec"
20 recrec = re.compile(recre)
21
22 def name_in_time(filename, timerange):
23 "Checks whether filename is a ttyrec with time between Unix times \
24 timerange[0] and timerange[1]."
25 nmatch = recrec.match(filename)
26 if not nmatch:
27 return False
28 ntime = calendar.timegm([int(val) for val in nmatch.groups()])
29 if ntime > timerange[0] and ntime <= timerange[1]:
30 return True
31 else:
32 return False
33
34 def input_game(outf, selected=None):
35 "Prints the form components for selecting a game."
36 selstr = '<option label="{0}" value="{1}" selected="selected">{0}</option>\n'
37 unselstr = '<option label="{0}" value="{1}">{0}</option>\n'
38 outf.write('<div>Dungeon name: <select name="game">\n')
39 for game in rlgall.gamelist:
40 # This will cause trouble if someone puts games with identical names
41 # into rlgall.
42 if selected and selected == game.uname:
43 outf.write(selstr.format(game.name, game.uname))
44 else:
45 outf.write(unselstr.format(game.name, game.uname))
46 outf.write('</select></div>\n')
47 return
48
49 def input_name(outf, defaultval=None):
50 defstr = '<div>Adventurer\'s name: <input type="text" name="name" value="{0}"></div>\n'
51 if defaultval:
52 outf.write(defstr.format(defaultval))
53 else:
54 outf.write('<div>Adventurer\'s Name: <input type="text" name="name"></div>\n')
55 return
56
57 def input_time(outf, defaultval=None):
58 defstr = '<div>Time: <input type="text" name="time" value="{0}"></div>\n'
59 if defaultval:
60 outf.write(defstr.format(defaultval))
61 else:
62 outf.write('<div>Time: <input type="text" name="time"></div>\n')
63 return
64
65 def input_datetime(outf, dvals=[None, None, None, None, None, None]):
66 optstr = '<option value="{0}" label="{1}">{1}</option>\n'
67 soptstr = '<option value="{0}" label="{1}" selected="selected">{1}</option>\n'