view py/recorder.py @ 2:8f49df4074d7

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.
author John "Elwin" Edwards <elwin@sdf.org>
date Thu, 26 Jul 2012 08:07:00 -0700
parents 5ba2123d2c20
children a943cfdfbad9
line wrap: on
line source

#!/usr/bin/python

import os
import time
import calendar
import psycopg2
import rlgalldb as rlgall

# Contains a dir for everyone who registered
everydir = "/var/dgl/dgldir/ttyrec/"
# Contains a page for everyone we know about
#knowndir = rlgall.dbdir + "players/"

# Contact the database
conn = psycopg2.connect("dbname=rlg")
cur = conn.cursor()

# newnames is the list of newly registered players who are not yet in the
# database.  updatenames is the set of players whose pages need updating.
cur.execute("SELECT pname FROM players;")
playersInDB = [ row[0] for row in cur.fetchall() ]
playersAll = os.listdir(everydir)
newnames = [ name for name in playersAll if name not in playersInDB ]
updatenames = set(newnames)

# Add the new names to the database
for newplayer in newnames:
  cur.execute("INSERT INTO players VALUES (%s);", [newplayer])
conn.commit()
cur.close()
conn.close()

# Update the database for each game.
for game in rlgall.gamelist:
  updatenames.update(game.loadnew())

# All the databases have been updated.  Now make the pages.

# Currently the high scores for all the games are on the same page.  If 
# they split up, this will have to change to a Game method.
rlgall.highpage()

for name in updatenames:
  rlgall.playerpage(name)

exit()