Mercurial > hg > rlgallery-misc
annotate py/cleandb.py @ 50:4549b3c0cd28
rlgall.py: add time selection to Game.getHigh().
Optional inittime and finaltime parameters set the range of time over
which to calculate high scores.
| author | John "Elwin" Edwards | 
|---|---|
| date | Fri, 28 Mar 2014 09:33:49 -0700 | 
| parents | 25843238434a | 
| children | 
| rev | line source | 
|---|---|
| 30 | 1 #!/usr/bin/python3 | 
| 
0
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
2 # cleandb.py: empty the database in an orderly fashion | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
3 | 
| 
33
 
25843238434a
Change the Python module's name back to rlgall.
 
John "Elwin" Edwards 
parents: 
30 
diff
changeset
 | 
4 import rlgall | 
| 
0
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
5 import psycopg2 | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
6 | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
7 dbconn = psycopg2.connect("dbname=rlg") | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
8 dbcur = dbconn.cursor() | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
9 | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
10 dbcur.execute("UPDATE games SET offbytes = %s", [0]) | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
11 | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
12 for game in rlgall.gamelist: | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
13 dbcur.execute("DELETE FROM " + game.uname + ";") | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
14 | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
15 dbcur.execute("DELETE FROM players;") | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
16 dbconn.commit() | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
17 | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
18 dbcur.close() | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
19 dbconn.close() | 
| 
 
5ba2123d2c20
Put this project under version control, finally.
 
John "Elwin" Edwards <elwin@sdf.org> 
parents:  
diff
changeset
 | 
20 exit() | 
