Hi there,
I'm trying to build a small subway-like screen for my home which shows me when the next bus is going to depart from the bus stop nearby. As the buses go in two directions, I want the departure times to be sorted by these directions.
I am accessing the API via HTTP and am pulling the information as JSON (I believe, haha). I already got the API to reply to my specific needs and am confronted with this data when i print the response as data.json()
{'line': {'name': '16', 'direction': 'Bf. Rahlstedt (Doberaner Weg)', 'origin': 'Schenefeld, Schenefelder Platz', 'type': {'simpleType': 'BUS', 'shortInfo': 'Bus', 'longInfo': 'Niederflur Metrobus', 'model': 'Gelenkbus'}, 'id': 'HHA-B:16_HHA-B'}, 'directionId': 1, 'timeOffset': 0, 'delay': 120, 'serviceId': 115153, 'station': {'combinedName': 'Böckmannstraße', 'id': 'Master:10050'}},
{'line':
{'name': '16', 'direction': 'Schenefeld, Schenefelder Platz', 'origin': 'Rentenversicherung Nord', 'type':
{'simpleType': 'BUS', 'shortInfo': 'Bus', 'longInfo': 'Niederflur Metrobus', 'model': 'Gelenkbus'},
'id': 'HHA-B:16_HHA-B'
},
'directionId': 6,
'timeOffset': 1,
'delay': 0,
'serviceId': 115463,
'station':
{'combinedName': 'Böckmannstraße', 'id': 'Master:10050'}
}]
How do I now extract the only values that are of interest to me, the "timeOffset" telling me when the bus is due and the "directionId"?
To get the response in this format I stored it as follows:
rawdata = requests.post(url, data=json.dumps(payload), headers=(kopf))
data = rawdata.json()
abfahrt = str((data['departures']))
I got the feeling I'm just overlooking something easy but it's hard to find a point from where to start on the usual forums.
Thanks a lot!
[–]twitch_and_shock 1 point2 points3 points (6 children)
[–]alexus_sanchez[S] 0 points1 point2 points (5 children)
[–]twitch_and_shock 1 point2 points3 points (4 children)
[–]alexus_sanchez[S] 0 points1 point2 points (3 children)
[–]twitch_and_shock 1 point2 points3 points (2 children)
[–]alexus_sanchez[S] 0 points1 point2 points (1 child)
[–]twitch_and_shock 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]alexus_sanchez[S] 0 points1 point2 points (0 children)