Browse Source

refactoring of the form data processing

* now a for loop, where we iterate over the keys of the queries dict
* when a key is found in the form queries, we set it to the form value
master
T. Meissner 12 years ago
parent
commit
01dd1cebf2
1 changed files with 18 additions and 25 deletions
  1. +18
    -25
      scripts/abfahrtsmonitor.py

+ 18
- 25
scripts/abfahrtsmonitor.py View File

@ -10,42 +10,35 @@ import urllib2
form = cgi.FieldStorage()
url = "http://widgets.vvo-online.de/abfahrtsmonitor/"
querytype = ""
ort = ""
hst = ""
vz = ""
vm = ""
timestamp = ""
query = ""
queries = {
"ort": "",
"hst": "",
"vz": "",
"vm": "",
"timestamp": ""
}
# available server scripts = valid queries
validqueries = ["haltestelle.do", "abfahrten.do"]
# check for queries
if (form.getvalue('query')):
query = form.getvalue('query')
if (form.getvalue('ort')):
ort = form.getvalue('ort')
if (form.getvalue('hst')):
hst = form.getvalue('hst')
if (form.getvalue('vz')):
vz = form.getvalue('vz')
if (form.getvalue('vm')):
vm = form.getvalue('vm')
if (form.getvalue('timestamp')):
timestamp = form.getvalue('timestamp')
validqueries = ["haltestelle.do", "abfahrten.do"]
queries = {
"ort": ort,
"hst": hst,
"vz": vz,
"vm": vm,
"timestamp": timestamp
}
for key in queries.viewkeys():
if (form.getvalue(key)):
queries[key] = form.getvalue(key)
# call the vvo server if the query is valid
if (query in validqueries):
url += query + "?" + urllib.urlencode(queries)
data = urllib2.urlopen(url).read()
else:
data = "[]"
# return the http response with the data received from server
# or an empty array if query was invalid
print("Content-type: text/html\n\n")
print(data)

Loading…
Cancel
Save