Mercurial > hg > rlgallery-misc
comparison py/rlgalldb.py @ 3:a943cfdfbad9
Remove obsolete code.
Remove some unnecessary module imports and code that worked with UNIX
timestamps.
| author | John "Elwin" Edwards <elwin@sdf.org> |
|---|---|
| date | Thu, 26 Jul 2012 09:35:07 -0700 |
| parents | def7fecbd437 |
| children | f5a37cc7f41f |
comparison
equal
deleted
inserted
replaced
| 2:8f49df4074d7 | 3:a943cfdfbad9 |
|---|---|
| 1 # rlgalldb.py | 1 # rlgalldb.py |
| 2 # Module for the Roguelike Gallery, using a postgres database | 2 # Module for the Roguelike Gallery, using a postgres database |
| 3 | 3 |
| 4 import os | 4 import os |
| 5 import sys | |
| 6 import time | 5 import time |
| 7 import calendar | 6 import calendar |
| 8 import re | |
| 9 import psycopg2 | 7 import psycopg2 |
| 10 from datetime import datetime, tzinfo, timedelta | 8 from datetime import datetime, tzinfo, timedelta |
| 11 | 9 |
| 12 # Configuration | 10 # Configuration |
| 13 logdir = "/var/dgl/var/games/roguelike/" | 11 logdir = "/var/dgl/var/games/roguelike/" |
| 68 try: | 66 try: |
| 69 conn = psycopg2.connect("dbname=rlg") | 67 conn = psycopg2.connect("dbname=rlg") |
| 70 except psycopg2.OperationalError: | 68 except psycopg2.OperationalError: |
| 71 return None | 69 return None |
| 72 return conn | 70 return conn |
| 73 | |
| 74 def recnameToInt(filename): | |
| 75 recre = r"(\d{4})-(\d{2})-(\d{2})\.(\d{2}):(\d{2}):(\d{2})\.ttyrec$" | |
| 76 match = re.match(recre, filename) | |
| 77 if not match: | |
| 78 return None | |
| 79 return calendar.timegm([int(val) for val in match.groups()]) | |
| 80 | 71 |
| 81 def recnameToTS(filename): | 72 def recnameToTS(filename): |
| 82 pattern = "%Y-%m-%d.%H:%M:%S.ttyrec" | 73 pattern = "%Y-%m-%d.%H:%M:%S.ttyrec" |
| 83 try: | 74 try: |
| 84 dt = datetime.strptime(filename, pattern).replace(tzinfo=utc) | 75 dt = datetime.strptime(filename, pattern).replace(tzinfo=utc) |
