I am trying to elegantly extract a very simple dictionary from a rather complex one, more specifically, Transport for London (TfL) provides an API with the status of the underground (tube). But the response is so long that my ESP32 cant handle it. Hence I have written a python script that reads the API response and deletes unused elements of the dictiionary like so
for x in linestatus: del x['lineStatuses'][0]['$type']
However I realize this is far from pretty and I am looking for a solution similar to this: Extract subset of key-value pairs from Python dictionary object?
But I cant get my head around how to do it with this specific dictionary. Here is the dict/JSON https://api.tfl.gov.uk/line/mode/tube/status
I would like to extract a simple dictionary only with
[{'name':'Bakerloo','statusSeverityDescription':'Part Suspended'}, {..}...]
with the maximum 'statusSeverity'
per line and only those disruptions where the ['validityPeriod']['isNow']
is true.
For clarification see the picture....
many thanks - trying to learn...