/[theodore]/openticket/ticketserver.cgi


UCC Code Repository

Contents of /openticket/ticketserver.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (show annotations) (download)
Fri Feb 1 04:56:07 2008 UTC (13 years, 5 months ago) by theodore
File size: 2822 byte(s)
Adding openticket base


1 #!/usr/bin/python
2 import cgi
3 import cgitb; cgitb.enable()
4 import time
5 import datetime
6
7 def savequeue(queuetosave):
8 # Format Queue to JSON format
9 outputfile = "{queue:[\n"
10 for item in queuetosave:
11 (qname, qsessionID, qtime) = item
12 outputfile += '{name:"%s", sessionID:"%s",time:"%s"},\n' % (qname, qsessionID, qtime)
13 outputfile += "]}"
14 file = open('queue.q', 'w')
15 file.write(outputfile)
16 file.close()
17 return True
18
19 def loadqueue():
20 newqueue = []
21 file = open('queue.q')
22 for line in file:
23 line = line.split(',')
24 try:
25 (qname,qsessionID,qtime) = (line[0], line[1], line[2])
26 except:
27 continue #If we can't break the line as above, then it is either the first or last line. Thus drop it.
28 qname = qname.split('"')[1]
29 qsessionID = qsessionID.split('"')[1]
30 qtime = qtime.split('"')[1]
31 newqueue.append((qname,qsessionID,qtime))
32 return newqueue
33
34 def hascurrentrequest():
35 i = 1
36 for (qname, qsessionID, qtime) in queue:
37 if qsessionID == sessionID:
38 return (qtime, ordinalize(i))
39 i += 1
40 return False
41
42 def makenewrequest():
43 currenttime = str(time.time())[:-3]
44 queue.append((name, sessionID, currenttime))
45 savequeue(queue)
46 return (currenttime, name, ordinalize(len(queue)))
47
48 def ordinalize(number):
49 string = str(number)
50 ones = number % 10
51 tens = number // 10 % 10
52 if ones == 1 and tens == 0:
53 string +="st"
54 elif ones == 2 and tens == 0:
55 string +="nd"
56 elif ones == 3 and tens == 0:
57 string +="rd"
58 else:
59 string +="th"
60 return string
61
62 def deleterequests():
63 newqueue = []
64 for item in queue:
65 (qname, qsessionID, qtime) = item
66 if qsessionID != sessionID:
67 newqueue.append(item)
68 savequeue(newqueue)
69
70 form = cgi.FieldStorage()
71 httpheader = "Status: 200\nContent-Type: text/html\r\n\n" # HTML is following
72 pagetoreturn = httpheader
73 queue = loadqueue()
74
75 if form.has_key('sessionID'):
76 sessionID = form['sessionID'].value
77 else:
78 sessionID = False
79 if form.has_key('request'):
80 request = form['request'].value
81 else:
82 request = False
83 if form.has_key('name'):
84 name = form['name'].value
85 else:
86 name = 'Nameless Worker Drone'
87
88 if sessionID:
89 currentrequest = hascurrentrequest()
90 if currentrequest and request != "delete":
91 pagetoreturn = "You're currently have an outstanding request. This was made at %s and is currently %s request oustanding." % currentrequest
92 else:
93 if request == "add":
94 newrequest = makenewrequest()
95 pagetoreturn = "Request recieved at %s from %s and is currently %s request oustanding" % newrequest
96 elif request == "delete":
97 deleterequests()
98 pagetoreturn = "All of your current tickets have been deleted."
99 else:
100 pagetoreturn = "You have no current ticket waiting in the queue. To request a queue press the 'Request Ticket' button."
101 else:
102 pagetoreturn = "Invalid Request, no Session ID present"
103
104 print httpheader + pagetoreturn
105

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26