status.py

This script outputs (in plain text) a space-delimited list of current user profiles.

Try it: run script


01: #!/usr/bin/python
02: import MySQLdb
03: import dbname
04: import sys
05: import cgitb # CGI traceback module
06: cgitb.enable()
07: 
08: sys.stderr = sys.stdout
09: 
10: 
11: print "Content-Type: Text/plain"
12: print
13: 
14: db = dbname.dbopen();
15: if (not db): sys.exit(1)
16: cursor = db.cursor()
17: try:
18:     cursor.execute ("SELECT modified, nickname, red, green, blue, xloc, yloc, message FROM users")
19: except MySQLdb.Error, e:
20:     print e
21: 
22: rows = cursor.fetchall()
23: for row in rows:
24:     if (row[0]): modified = row[0]
25:     else: modified=''
26:     if (row[1]): nickname = row[1]
27:     else: nickname = ''
28:     if (row[2]): red = int(row[2])
29:     else: red = 0
30:     if (row[3]): green = int(row[3])
31:     else: green = 0
32:     if (row[4]): blue = int(row[4])
33:     else: blue = 0
34:     if (row[5]): xloc = float(row[5])
35:     else: xloc = 0.0
36:     if (row[6]): yloc = float(row[6])
37:     else: yloc = 0.0
38:     if (row[7]): message = row[7]
39:     else: message = ''
40:     rs = (modified, nickname, red, green, blue, xloc, yloc, message)
41:     print '"%s" "%s" %d %d %d %g %g "%s"' % rs
42: cursor.close()
43: db.close()


Maintained by John Loomis, updated Mon Mar 03 11:33:03 2008