Some experiments with web applications

abfahrtsmonitor.py 901B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-1 -*-
  3. import cgi
  4. import urllib
  5. import urllib2
  6. # get cgi object
  7. form = cgi.FieldStorage()
  8. url = "http://widgets.vvo-online.de/abfahrtsmonitor/"
  9. query = ""
  10. queries = {
  11. "ort": "",
  12. "hst": "",
  13. "vz": "",
  14. "vm": "",
  15. "timestamp": ""
  16. }
  17. # available server scripts = valid queries
  18. validqueries = ["haltestelle.do", "abfahrten.do"]
  19. # check for queries
  20. if (form.getvalue('query')):
  21. query = form.getvalue('query')
  22. for key in queries:
  23. if (form.getvalue(key)):
  24. queries[key] = form.getvalue(key)
  25. # call the vvo server if the query is valid
  26. if (query in validqueries):
  27. url += query + "?" + urllib.urlencode(queries)
  28. data = urllib2.urlopen(url).read()
  29. else:
  30. data = "[]"
  31. # return the http response with the data received from server
  32. # or an empty array if query was invalid
  33. print("Content-type: text/html\n\n")
  34. print(data)