# HG changeset patch # User John "Elwin" Edwards # Date 1347914470 25200 # Node ID 453278a81371b470b647bbadda626d2ad583c64e # Parent c05050f78d81dd24b4374659f04b4247a39c20f4 Add tablerecent() so recent.cgi will work as before. Port the tablerecent() function, which reads the most recent games directly from the logfile instead of the database. This allows recent.cgi to show games immediately without waiting for the recorder to put them in the database. diff -r c05050f78d81 -r 453278a81371 py/rlgalldb.py --- a/py/rlgalldb.py Mon Sep 17 11:41:11 2012 -0700 +++ b/py/rlgalldb.py Mon Sep 17 13:41:10 2012 -0700 @@ -171,7 +171,6 @@ break entlist.append(self.logtoDict(nextentry)) return - # TODO how does this work with postprocess? def loadnew(self): conn = getconn() if conn == None: @@ -239,6 +238,29 @@ conn.commit() cur.close() return + def tablerecent(self, of): + "Prints the most recent games from the logfile, NOT the database." + newest = [] + try: + scr = open(self.scores) + except IOError: + pass + else: + try: + scr.seek(self.lookback, 2) + except IOError: + scr.seek(0) # The file wasn't that long, start at the beginning + if scr.tell() != 0: + scr.readline() # Throw away the incomplete line + self.getEntryDicts(scr, newest) + newest.reverse() + scr.close() + of.write(secthead.format(self.name)) + if not newest: + of.write("
No one has braved this dungeon yet.
\n") + else: + printTable(newest, self.fields, of) + return # End Game class definition class RogueGame(Game): @@ -251,6 +273,7 @@ "name": "varchar(20)", "xl": "int", "fate": "text", "ttyrecs": "text ARRAY", "startt": "timestamptz"} self.logdelim = " " + self.lookback = -1500 colspec = "(" valspec = "(" for i, col in enumerate(self.sqltypes.keys()): @@ -379,6 +402,7 @@ "maxdepth": "int", "quest": "int", "hadquest": "bool", "fate": "text", "ttyrecs": "text ARRAY", "startt": "timestamptz"} self.logdelim = " " + self.lookback = -1800 colspec = "(" valspec = "(" for i, col in enumerate(self.sqltypes.keys()): diff -r c05050f78d81 -r 453278a81371 web/recent.cgi --- a/web/recent.cgi Mon Sep 17 11:41:11 2012 -0700 +++ b/web/recent.cgi Mon Sep 17 13:41:10 2012 -0700 @@ -3,7 +3,7 @@ import sys import time -import rlgall +import rlgalldb as rlgall # The required header sys.stdout.write("Content-type: text/html\r\n\r\n")