mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
first cut at script to fetch messages for a game
This commit is contained in:
parent
ed41fdd924
commit
5f34fe3317
1 changed files with 41 additions and 0 deletions
41
xwords4/relay/scripts/msgs.py
Executable file
41
xwords4/relay/scripts/msgs.py
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# Script meant to be installed on eehouse.org.
|
||||||
|
|
||||||
|
import getpass, logging, shelve, hashlib, sys, json, subprocess, psycopg2
|
||||||
|
try:
|
||||||
|
from mod_python import apache
|
||||||
|
apacheAvailable = True
|
||||||
|
except ImportError:
|
||||||
|
apacheAvailable = False
|
||||||
|
|
||||||
|
# I'm not checking my key in...
|
||||||
|
import mykey
|
||||||
|
|
||||||
|
def init():
|
||||||
|
global g_sent
|
||||||
|
try:
|
||||||
|
con = psycopg2.connect(port=mykey.psqlPort, database='xwgames', user=getpass.getuser())
|
||||||
|
except psycopg2.DatabaseError, e:
|
||||||
|
print 'Error %s' % e
|
||||||
|
sys.exit(1)
|
||||||
|
return con
|
||||||
|
|
||||||
|
|
||||||
|
def getForConnnameAndHID( connname, hid ):
|
||||||
|
con = init()
|
||||||
|
cur = con.cursor()
|
||||||
|
query = "SELECT msg64 FROM msgs WHERE connname='%s' AND hid=%d"
|
||||||
|
cur.execute(query % (connname, hid))
|
||||||
|
result = []
|
||||||
|
for row in cur:
|
||||||
|
result.append(row[0])
|
||||||
|
|
||||||
|
return json.dumps( result )
|
||||||
|
|
||||||
|
def main():
|
||||||
|
json = getForConnnameAndHID( 'eehouse.org:53042e07:129', 1 )
|
||||||
|
print json
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in a new issue