I'm about 2 days into Python (2.7 I think) and I'm trying to make the API response here a lot more readable, at the moment it's hard to decipher the English response.
import json, requests
response = requests.get("http://data.dublinked.ie/cgi-
bin/rtpi/realtimebusinformation?stopid=1341&routeid=49&format=json")
data = response.json()
print data
The response is this, and it's very ugly :( I would like to A) format it so it's more readable, maybe in a list or key:value pair? B) How do pick only certain information from the response?
numberofresults: 2
timestamp: 16/01/2018 17:04:15
errormessage:
results: [{u'origin': u'Tallaght', u'direction': u'Inbound',
u'destinationlocalized': u'Sr\xe1id an Phiarsaigh', u'monitored': u'true',
u'departureduetime': u'6', u'route': u'49', u'additionalinformation': u'',
u'destination': u'Pearse St', u'scheduleddeparturedatetime': u'16/01/2018
17:09:00', u'scheduledarrivaldatetime': u'16/01/2018 17:09:00',
u'sourcetimestamp': u'16/01/2018 17:01:53', u'operator': u'bac',
u'departuredatetime': u'16/01/2018 17:10:56', u'arrivaldatetime':
u'16/01/2018 17:10:56', u'lowfloorstatus': u'no', u'originlocalized':
u'Tamhlacht', u'duetime': u'6'}, {u'origin': u'Tallaght', u'direction':
u'Inbound', u'destinationlocalized': u'Sr\xe1id an Phiarsaigh',
u'monitored': u'true', u'departureduetime': u'37', u'route': u'49',
u'additionalinformation': u'', u'destination': u'Pearse St',
u'scheduleddeparturedatetime': u'16/01/2018 17:42:00',
u'scheduledarrivaldatetime': u'16/01/2018 17:42:00', u'sourcetimestamp':
u'16/01/2018 16:43:44', u'operator': u'bac', u'departuredatetime':
u'16/01/2018 17:42:13', u'arrivaldatetime': u'16/01/2018 17:42:13',
u'lowfloorstatus': u'no', u'originlocalized': u'Tamhlacht', u'duetime':
u'37'}]
errorcode: 0
stopid: 1341
[Finished in 0.7s]
I'm most probably doubling up on a question/answer but I can't seem to find it! Sorry. Also, the "u" is something I don't understand either.
Thank you all in advance x