Browse Source

begin to develop support for getting station names

* new query: query which contains the wished server script to call
* query can contain 'haltestelle.do' or 'abfahrten.do'
* all other values are rejected and answered with empty array
T. Meissner 7 years ago
parent
commit
e575e57ffb
1 changed files with 13 additions and 4 deletions
  1. 13
    4
      scripts/abfahrtsmonitor.py

+ 13
- 4
scripts/abfahrtsmonitor.py View File

@@ -9,6 +9,8 @@ import urllib2
9 9
 # get cgi object
10 10
 form = cgi.FieldStorage()
11 11
 
12
+url = "http://widgets.vvo-online.de/abfahrtsmonitor/"
13
+querytype = ""
12 14
 ort = ""
13 15
 hst = ""
14 16
 vz = ""
@@ -16,17 +18,21 @@ vm = ""
16 18
 timestamp = ""
17 19
 
18 20
 # check for queries
21
+if (form.getvalue('query')):
22
+    query = form.getvalue('query')
19 23
 if (form.getvalue('ort')):
20 24
     ort = form.getvalue('ort')
21 25
 if (form.getvalue('hst')):
22 26
     hst = form.getvalue('hst')
23 27
 if (form.getvalue('vz')):
24 28
     vz = form.getvalue('vz')
25
-if (form.getvalue('vz')):
26
-    vm = form.getvalue('vz')
29
+if (form.getvalue('vm')):
30
+    vm = form.getvalue('vm')
27 31
 if (form.getvalue('timestamp')):
28 32
     timestamp = form.getvalue('timestamp')
29 33
 
34
+validqueries = ["haltestelle.do", "abfahrten.do"]
35
+
30 36
 queries = {
31 37
     "ort": ort,
32 38
     "hst": hst,
@@ -35,8 +41,11 @@ queries = {
35 41
     "timestamp": timestamp
36 42
 }
37 43
 
38
-url = "http://widgets.vvo-online.de/abfahrtsmonitor/Abfahrten.do?" + urllib.urlencode(queries)
39
-data = urllib2.urlopen(url).read()
44
+if (query in validqueries):
45
+    url += query + "?" + urllib.urlencode(queries)
46
+    data = urllib2.urlopen(url).read()
47
+else:
48
+    data = "[]"
40 49
 
41 50
 print("Content-type: text/html\n\n")
42 51
 print(data)