Mercurial > hg > rlgallery-misc
comparison web/archive.cgi @ 30:e8f3b7994d88
Port to Python 3.
All scripts and modules have been ported to Python 3 and appear to
work.  Some changes to the lighttpd configuration were needed.
| author | John "Elwin" Edwards | 
|---|---|
| date | Tue, 31 Dec 2013 13:36:19 -0500 | 
| parents | 4778ab7de7aa | 
| children | 25843238434a | 
   comparison
  equal
  deleted
  inserted
  replaced
| 29:23a769aa487e | 30:e8f3b7994d88 | 
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python3 | 
| 2 | 2 | 
| 3 import cgi | 3 import cgi | 
| 4 import os | 4 import os | 
| 5 import sys | 5 import sys | 
| 6 import time | 6 import time | 
| 7 import calendar | 7 import calendar | 
| 8 from datetime import datetime | 8 from datetime import datetime | 
| 9 import pytz | |
| 9 import rlgalldb as rlgall | 10 import rlgalldb as rlgall | 
| 10 #import cgitb | 11 #import cgitb | 
| 11 | 12 | 
| 12 #cgitb.enable() | 13 #cgitb.enable() | 
| 13 | 14 | 
| 53 soptstr = '<option value="{0}" label="{1}" selected="selected">{1}</option>\n' | 54 soptstr = '<option value="{0}" label="{1}" selected="selected">{1}</option>\n' | 
| 54 tf = '<input type="text" size="2" maxlength="2" name="{0}" value="{1:02}">' | 55 tf = '<input type="text" size="2" maxlength="2" name="{0}" value="{1:02}">' | 
| 55 emptf = '<input type="text" size="2" maxlength="2" name="{0}">' | 56 emptf = '<input type="text" size="2" maxlength="2" name="{0}">' | 
| 56 sstr = '<div>Date: <select name="year">\n' | 57 sstr = '<div>Date: <select name="year">\n' | 
| 57 # Default to today | 58 # Default to today | 
| 58 now = datetime.now(rlgall.utc) | 59 now = datetime.now(pytz.utc) | 
| 59 if dvals[0] == None: | 60 if dvals[0] == None: | 
| 60 dvals[0] = now.year | 61 dvals[0] = now.year | 
| 61 if dvals[1] == None: | 62 if dvals[1] == None: | 
| 62 dvals[1] = now.month | 63 dvals[1] = now.month | 
| 63 if dvals[2] == None: | 64 if dvals[2] == None: | 
| 162 utime = 0 | 163 utime = 0 | 
| 163 if utime != None: | 164 if utime != None: | 
| 164 chtime = time.gmtime(utime) | 165 chtime = time.gmtime(utime) | 
| 165 for i in range(6): | 166 for i in range(6): | 
| 166 hlist[i] = chtime[i] | 167 hlist[i] = chtime[i] | 
| 167 return datetime.fromtimestamp(utime, rlgall.utc) | 168 return datetime.fromtimestamp(utime, pytz.utc) | 
| 168 | 169 | 
| 169 # Now try to get a human-readable specification. | 170 # Now try to get a human-readable specification. | 
| 170 lerrors = [] | 171 lerrors = [] | 
| 171 year = month = day = hour = minute = second = None | 172 year = month = day = hour = minute = second = None | 
| 172 fyear = fdata.getfirst("year") | 173 fyear = fdata.getfirst("year") | 
| 259 hlist[5] = second | 260 hlist[5] = second | 
| 260 if lerrors: | 261 if lerrors: | 
| 261 errlist.extend(lerrors) | 262 errlist.extend(lerrors) | 
| 262 return None | 263 return None | 
| 263 #return calendar.timegm([year, month, day, hour, minute, second, 0, 0, 0]) | 264 #return calendar.timegm([year, month, day, hour, minute, second, 0, 0, 0]) | 
| 264 return datetime(year, month, day, hour, minute, second, 0, rlgall.utc) | 265 return datetime(year, month, day, hour, minute, second, 0, pytz.utc) | 
| 265 | 266 | 
| 266 # Begin processing | 267 # Begin processing | 
| 267 fdata = cgi.FieldStorage() | 268 fdata = cgi.FieldStorage() | 
| 268 | 269 | 
| 269 # If this is true, the user didn't supply any search criteria, so assume it | 270 # If this is true, the user didn't supply any search criteria, so assume it | 
| 305 gamefiles = result[0] | 306 gamefiles = result[0] | 
| 306 cur.close() | 307 cur.close() | 
| 307 conn.close() | 308 conn.close() | 
| 308 | 309 | 
| 309 # Now we are ready to print the page. | 310 # Now we are ready to print the page. | 
| 310 sys.stdout.write("Content-type: text/html\r\n\r\n") | 311 sys.stdout.write("Content-Type: text/html; charset=utf-8\r\n\r\n") | 
| 311 | 312 | 
| 312 sys.stdout.write(rlgall.phead.format("Archive")) | 313 sys.stdout.write(rlgall.phead.format("Archive")) | 
| 313 sys.stdout.write(rlgall.ptop) | 314 sys.stdout.write(rlgall.ptop) | 
| 314 sys.stdout.write(rlgall.navtop.format("Archive")) | 315 sys.stdout.write(rlgall.navtop.format("Archive")) | 
| 315 sys.stdout.write('<div class="content">\n') | 316 sys.stdout.write('<div class="content">\n') | 
