Mercurial > hg > rlgallery-misc
changeset 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 | def7fecbd437 |
| files | py/cleandb.py py/recorder.py py/rlgalldb.py py/setupdb.py py/stats.py web/archive.cgi |
| diffstat | 6 files changed, 937 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/py/cleandb.py Wed Jul 25 21:59:42 2012 -0700 @@ -0,0 +1,20 @@ +#!/usr/bin/python +# cleandb.py: empty the database in an orderly fashion + +import rlgalldb as rlgall +import psycopg2 + +dbconn = psycopg2.connect("dbname=rlg") +dbcur = dbconn.cursor() + +dbcur.execute("UPDATE games SET offbytes = %s", [0]) + +for game in rlgall.gamelist: + dbcur.execute("DELETE FROM " + game.uname + ";") + +dbcur.execute("DELETE FROM players;") +dbconn.commit() + +dbcur.close() +dbconn.close() +exit()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/py/recorder.py Wed Jul 25 21:59:42 2012 -0700 @@ -0,0 +1,46 @@ +#!/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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/py/rlgalldb.py Wed Jul 25 21:59:42 2012 -0700 @@ -0,0 +1,425 @@ +# rlgalldb.py +# Module for the Roguelike Gallery, using a postgres database + +import os +import sys +import time +import calendar +import re +import psycopg2 +from datetime import datetime, tzinfo, timedelta + +# Configuration +logdir = "/var/dgl/var/games/roguelike/" +webdir = "/var/www/lighttpd/scoring/" +ppagename = webdir + "players/{0}.html" +hpagename = webdir + "highscores.html" + +# HTML fragments for templating +phead = """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html><head> +<title>{0}</title> +<link rel="stylesheet" href="/scoring/scores.css" type="text/css"> +</head> +""" + +ptop = """<body> +<h1>Yendor Guild</h1> +"""
