-
Notifications
You must be signed in to change notification settings - Fork 0
/
kivyTNW_06.py
122 lines (108 loc) · 3.23 KB
/
kivyTNW_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.properties import StringProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.network.urlrequest import UrlRequest
Builder.load_string('''
<queryTNW>:
Button:
text: "update Blaesiring"
text_size: self.width, None
halign: 'center'
on_press: root.lookup("Blaesiring")
size_hint_x: 0.25
Label:
text: root.foundA
text_size: self.width, None
padding_x: 10
Button:
text: "update Erasmusplatz"
text_size: self.width, None
halign: 'center'
on_press: root.lookup("Erasmusplatz")
size_hint_x: 0.25
Label:
text: root.foundB
text_size: self.width, None
padding_x: 10
Button:
text: "update Johanniterbruecke"
text_size: self.width, None
halign: 'center'
on_press: root.lookup("Johanniterbruecke")
size_hint_x: 0.25
Label:
text: root.foundC
text_size: self.width, None
padding_x: 10
Button:
text: "update Freilager"
text_size: self.width, None
halign: 'center'
on_press: root.lookup("Freilager")
size_hint_x: 0.25
Label:
text: root.foundD
text_size: self.width, None
padding_x: 10
''')
stA = "Blaesiring"
stB = "Erasmusplatz"
stC = "Johanniterbruecke"
stD = "Freilager"
urlStation = "http://transport.opendata.ch/v1/stationboard?station="
class queryTNW(GridLayout, Screen):
foundA = StringProperty("")
foundB = StringProperty("")
foundC = StringProperty("")
foundD = StringProperty("")
def __init__(self, **kwargs):
super(queryTNW, self).__init__(**kwargs)
self.cols = 2
self.foundA = ""
self.foundB = ""
self.foundC = ""
self.foundD = ""
def req(*args):
r = UrlRequest(urlStation + args[1])
r.wait()
jData = r.result
stb = jData.get("stationboard")
accuStr = []
for i in range(len(stb)):
tName = stb[i].get("name")
tDest = stb[i].get("to")
tDepTime = stb[i].get("stop").get("departure")
displayStr = tName + ", "
displayStr += tDepTime[11:16] + ", "
displayStr += tDest
if i < 7:
accuStr += "\n" + displayStr
return accuStr
def lookup(self, *args):
if args[0] == "Blaesiring":
self.foundA = ""
for line in self.req(stA):
self.foundA += line
elif args[0] == "Erasmusplatz":
self.foundB = ""
for line in self.req(stB):
self.foundB += line
elif args[0] == "Johanniterbruecke":
self.foundC = ""
for line in self.req(stC):
self.foundC += line
elif args[0] == "Freilager":
self.foundD = ""
for line in self.req(stD):
self.foundD += line
sm = ScreenManager()
sm.add_widget(queryTNW(name="queryTNW"))
class kivyTNW(App):
def build(self):
return sm
if __name__ == "__main__":
kivyTNW().run()