# HG changeset patch
# User John "Elwin" Edwards
# Date 1343315220 25200
# Node ID 8f49df4074d7ad41c8135d537f3d4aa1707f7ee5
# Parent def7fecbd437bba5bcf828d6ad5bc7e7d071291e
Convert web/archive.cgi to use the new SQL timestamps.
The Archivist has replaced UNIX timestamps with python datetime objects
derived from SQL timestamps. There are still a lot of struct_time
objects which should be converted too.
diff -r def7fecbd437 -r 8f49df4074d7 web/archive.cgi
--- a/web/archive.cgi Wed Jul 25 23:05:12 2012 -0700
+++ b/web/archive.cgi Thu Jul 26 08:07:00 2012 -0700
@@ -6,6 +6,7 @@
import re
import time
import calendar
+from datetime import datetime
import rlgalldb as rlgall
import cgitb
@@ -19,18 +20,6 @@
recre = r"(\d{4,4})-(\d{2,2})-(\d{2,2})\.(\d{2,2}):(\d{2,2}):(\d{2,2})\.ttyrec"
recrec = re.compile(recre)
-def name_in_time(filename, timerange):
- "Checks whether filename is a ttyrec with time between Unix times \
- timerange[0] and timerange[1]."
- nmatch = recrec.match(filename)
- if not nmatch:
- return False
- ntime = calendar.timegm([int(val) for val in nmatch.groups()])
- if ntime > timerange[0] and ntime <= timerange[1]:
- return True
- else:
- return False
-
def input_game(outf, selected=None):
"Prints the form components for selecting a game."
selstr = '\n'
@@ -153,9 +142,9 @@
return None
def processtime(fdata, errlist, hlist):
- "Takes a CGI data object and converts to a Unix timestamp by finding fields \
- called year, month, etc. Any errors get appended to errlist. hlist \
- should contain 6 components, for ymd-hms fields."
+ "Takes a CGI data object and converts to a datetime object by finding \
+ fields called year, month, etc. Any errors get appended to errlist. \
+ hlist should contain 6 components, for ymd-hms fields."
# Timestamp overrides human-readable, even if it's invalid.
badtime = 'The time field is for Unix clocks, which never say anything \
@@ -175,7 +164,7 @@
chtime = time.gmtime(utime)
for i in range(6):
hlist[i] = chtime[i]
- return utime
+ return datetime.fromtimestamp(utime, rlgall.utc)
# Now try to get a human-readable specification.
lerrors = []
@@ -271,7 +260,8 @@
if lerrors:
errlist.extend(lerrors)
return None
- return calendar.timegm([year, month, day, hour, minute, second, 0, 0, 0])
+ #return calendar.timegm([year, month, day, hour, minute, second, 0, 0, 0])
+ return datetime(year, month, day, hour, minute, second, 0, rlgall.utc)
# Begin processing
fdata = cgi.FieldStorage()
@@ -281,38 +271,37 @@
isnotsearch = checkempty(fdata)
errors = []
-formname = dungeon = utime = None
+formname = dungeon = searchtime = None
timepieces = [None, None, None, None, None, None]
if not isnotsearch:
formname = processname(fdata, errors)
dungeon = processgame(fdata, errors)
- utime = processtime(fdata, errors, timepieces)
+ searchtime = processtime(fdata, errors, timepieces)
-dosearch = formname != None and dungeon != None and utime != None
+dosearch = formname != None and dungeon != None and searchtime != None
# Find the actual files, and put them in a list called gamefiles.
gtimes = [0, int(time.time())]
relgame = None
gamefiles = []
if dosearch:
- ttyrecdir = "{0}/{1}/{2}/".format(ttyrecbase, formname, dungeon.uname)
- query1 = "SELECT ttyrecs FROM {0} WHERE name = %s AND stime <= %s AND etime >= %s;".format(dungeon.uname)
- query2 = "SELECT ttyrecs FROM {0} WHERE name = %s AND etime >= %s ORDER BY etime LIMIT 1;".format(dungeon.uname)
- query3 = "SELECT ttyrecs FROM {0} WHERE name = %s AND stime <= %s ORDER BY stime DESC LIMIT 1;".format(dungeon.uname)
+ query1 = "SELECT ttyrecs FROM {0} WHERE name = %s AND startt <= %s AND endt >= %s;".format(dungeon.uname)
+ query2 = "SELECT ttyrecs FROM {0} WHERE name = %s AND endt >= %s ORDER BY endt LIMIT 1;".format(dungeon.uname)
+ query3 = "SELECT ttyrecs FROM {0} WHERE name = %s AND startt <= %s ORDER BY startt DESC LIMIT 1;".format(dungeon.uname)
conn = rlgall.getconn()
cur = conn.cursor()
- cur.execute(query1, [formname, utime, utime])
+ cur.execute(query1, [formname, searchtime, searchtime])
result = cur.fetchone()
if result:
gamefiles = result[0]
else:
- cur.execute(query2, [formname, utime])
+ cur.execute(query2, [formname, searchtime])
result = cur.fetchone()
if result:
gamefiles = result[0]
else:
- cur.execute(query3, [formname, utime])
+ cur.execute(query3, [formname, searchtime])
result = cur.fetchone()
if result:
gamefiles = result[0]
@@ -331,7 +320,7 @@
if dosearch:
sys.stdout.write("
Expedition by {0} to {1} about {2}:
\n".format(
rlgall.playerlink(formname), dungeon.name,
- time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(utime))))
+ searchtime.strftime("%Y/%m/%d %H:%M:%S")))
if not gamefiles:
sys.stdout.write("