Mercurial > hg > rlgallery-misc
comparison py/recorder.py @ 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 | a943cfdfbad9 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:5ba2123d2c20 |
|---|---|
| 1 #!/usr/bin/python | |
| 2 | |
| 3 import os | |
| 4 import time | |
| 5 import calendar | |
| 6 import psycopg2 | |
| 7 import rlgalldb as rlgall | |
| 8 | |
| 9 # Contains a dir for everyone who registered | |
| 10 everydir = "/var/dgl/dgldir/ttyrec/" | |
| 11 # Contains a page for everyone we know about | |
| 12 #knowndir = rlgall.dbdir + "players/" | |
| 13 | |
| 14 # Contact the database | |
| 15 conn = psycopg2.connect("dbname=rlg") | |
| 16 cur = conn.cursor() | |
| 17 | |
| 18 # newnames is the list of newly registered players who are not yet in the | |
| 19 # database. updatenames is the set of players whose pages need updating. | |
| 20 cur.execute("SELECT pname FROM players;") | |
| 21 playersInDB = [ row[0] for row in cur.fetchall() ] | |
| 22 playersAll = os.listdir(everydir) | |
| 23 newnames = [ name for name in playersAll if name not in playersInDB ] | |
| 24 updatenames = set(newnames) | |
| 25 | |
| 26 # Add the new names to the database | |
| 27 for newplayer in newnames: | |
| 28 cur.execute("INSERT INTO players VALUES (%s);", [newplayer]) | |
| 29 conn.commit() | |
| 30 cur.close() | |
| 31 conn.close() | |
| 32 | |
| 33 # Update the database for each game. | |
| 34 for game in rlgall.gamelist: | |
| 35 updatenames.update(game.loadnew()) | |
| 36 | |
| 37 # All the databases have been updated. Now make the pages. | |
| 38 | |
| 39 # Currently the high scores for all the games are on the same page. If | |
| 40 # they split up, this will have to change to a Game method. | |
| 41 rlgall.highpage() | |
| 42 | |
| 43 for name in updatenames: | |
| 44 rlgall.playerpage(name) | |
| 45 | |
| 46 exit() |
