Hi all.
I am accessing data via an API and have the following structure
It actually contains 5000 locations and I want to search to find stuff …
Maybe to find sites in London, so looking at the unitaryAuthArea.
I am using Python 3.8
{'Locations':
{'Location':
[
{'elevation': '50.0', 'id': '14', 'latitude': '54.9375', 'longitude': '-2.8092', 'name': 'Carlisle Airport', 'region': 'nw', 'unitaryAuthArea': 'Cumbria'},
{'elevation': '22.0', 'id': '26', 'latitude': '53.3336', 'longitude': '-2.85', 'name': 'Liverpool John Lennon Airport', 'region': 'nw', 'unitaryAuthArea': 'Merseyside'},
{'elevation': '185.0', 'id': '354875', 'latitude': '51.8258', 'longitude': '-3.682', 'name': 'Craig Y Nos Country Park', 'nationalPark': 'Brecon Beacons National Park', 'region': 'wl', 'unitaryAuthArea': 'Powys'},
{'elevation': '201.0', 'id': '354876', 'latitude': '51.92', 'longitude': '-3.4644', 'name': 'Brecon Beacons Visitor Centre', 'nationalPark': 'Brecon Beacons National Park', 'region': 'wl', 'unitaryAuthArea': 'Powys'},
{'elevation': '694.0', 'id': '371597', 'latitude': '54.1558', 'longitude': '-2.2473', 'name': 'Pen-Y-Ghent', 'nationalPark': 'Yorkshire Dales National Park', 'region': 'yh', 'unitaryAuthArea': 'North Yorkshire'}, {'elevation': '71.0', 'id': '371604', 'latitude': '52.72429', 'longitude': '-2.84043', 'name': 'Preston Montford', 'region': 'wm', 'unitaryAuthArea': 'Shropshire'}, {'elevation': '62.0', 'id': '371608', 'latitude': '51.4413', 'longitude': '-0.9381', 'name': 'Reading University', 'region': 'se', 'unitaryAuthArea': 'Wokingham'}
]}}
I want to search this …
This is the function so far …
def sitelist(city):
myKey = '1XXXXXXXXXX46a-9c26ZXXXXdf'
url='http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/sitelist?key=' + myKey
response=requests.get(url)
print(response)
sitelist = response.json()
print('\n Location:', sitelist['Locations']['Location'][1]['name'])
I guess that I need to use a for loop somehow to search for the item ?
Any help much appreciated