Skip to content

Commit b91320f

Browse files
authored
Merge pull request #21 from sitistas/reallivedata
Downloading real data every 10s
2 parents 53c24c8 + 8a0df13 commit b91320f

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

bus.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def getLiveData(lineOperator, line_name, livedom):
133133
addresses.append(location.address.split(",")[0])
134134
return [latList, lonList, addresses]
135135

136+
def downloadLiveData(liveid,API_KEY):
137+
# Request για λήψη των live data
138+
r2 = requests.get(
139+
'https://data.bus-data.dft.gov.uk/api/v1/datafeed/{}/?api_key={}'.format(liveid,API_KEY))
140+
# Αποθήκευση δεδομένων σε xml
141+
open("livedata.xml", "wb").write(r2.content)
142+
livedom = xml.dom.minidom.parse("livedata.xml")
143+
return livedom
144+
136145

137146
API_KEY = os.getenv('API_KEY')
138147
# Το id του dataset των timetables
@@ -202,12 +211,8 @@ def getLiveData(lineOperator, line_name, livedom):
202211
stopsDict, JPSD, journeyPatterns, journeyPerDeparture, deptTime)
203212
print(stopsList)
204213

205-
# Request για λήψη των live data
206-
r2 = requests.get(
207-
'https://data.bus-data.dft.gov.uk/api/v1/datafeed/{}/?api_key={}'.format(liveid,API_KEY))
208-
# Αποθήκευση δεδομένων σε xml
209-
open("livedata.xml", "wb").write(r2.content)
210-
livedom = xml.dom.minidom.parse("livedata.xml")
214+
#Λήψη live δεδομένων
215+
livedom = downloadLiveData(liveid,API_KEY)
211216

212217
# Αποθήκευση συντεταγμένων live δεδομένων και δημιουργία server αν τα δεδομένα δεν είναι κενά
213218
[latList, lonList, addresses] = getLiveData(lineOperator, line_name, livedom)
@@ -229,11 +234,13 @@ def getLiveData(lineOperator, line_name, livedom):
229234
@app.callback(Output('live-update-graph', 'figure'),
230235
Input('interval-component', 'n_intervals'))
231236
def update_graph_live(interval):
232-
latList[0] += 0.0002
233-
fig = plotLiveData(latList, lonList, addresses)
237+
# latList[0] += 0.0002 #Fake motion if needed fow showcase
238+
livedom = downloadLiveData(liveid,API_KEY)
239+
[latList, lonList, addresses] = getLiveData(lineOperator, line_name, livedom)
240+
if len(latList)>0:
241+
fig = plotLiveData(latList, lonList, addresses)
234242
return fig
235243

236-
237244
app.run(
238245
host='0.0.0.0',
239246
port='8085')

0 commit comments

Comments
 (0)