I want to get the values of live data from the air quality london api however I don't know how to get the values from the strange dictionary like thing that is outputted.
Here is my code:
def get_live_data_from_api(site_code='MY1',species_code='NO',start_date=None,end_date=None):
start_date = datetime.date.today() if start_date is None else start_date
end_date = start_date + datetime.timedelta(days=1) if end_date is None else end_date
endpoint = "https://api.erg.ic.ac.uk/AirQuality/Data/SiteSpecies/SiteCode={site_code}/SpeciesCode={species_code}/StartDate={start_date}/EndDate={end_date}/Json"
url = endpoint.format(
site_code = site_code,
species_code = species_code,
start_date = start_date,
end_date = end_date
)
res = (requests.get(url)).json()
print(res)
here is the output:
{'RawAQData': {'@SiteCode': 'MY1', '@SpeciesCode': 'NO', 'Data': [{'@MeasurementDateGMT': '2022-12-24 00:00:00', '@Value': '13.5'}, {'@MeasurementDateGMT': '2022-12-24 01:00:00', '@Value': '9.8'}, {'@MeasurementDateGMT': '2022-12-24 02:00:00', '@Value': '8.7'}, {'@MeasurementDateGMT': '2022-12-24 03:00:00', '@Value': '7.9'}, {'@MeasurementDateGMT': '2022-12-24 04:00:00', '@Value': '8.1'}, {'@MeasurementDateGMT': '2022-12-24 05:00:00', '@Value': '10.1'}, {'@MeasurementDateGMT': '2022-12-24 06:00:00', '@Value': '19.7'}, {'@MeasurementDateGMT': '2022-12-24 07:00:00', '@Value': '22.1'}, {'@MeasurementDateGMT': '2022-12-24 08:00:00', '@Value': '24'}, {'@MeasurementDateGMT': '2022-12-24 09:00:00', '@Value': '34.2'}, {'@MeasurementDateGMT': '2022-12-24 10:00:00', '@Value': '32.2'}, {'@MeasurementDateGMT': '2022-12-24 11:00:00', '@Value': '42.2'}, {'@MeasurementDateGMT': '2022-12-24 12:00:00', '@Value': '41.8'}, {'@MeasurementDateGMT': '2022-12-24 13:00:00', '@Value': '33.2'}, {'@MeasurementDateGMT': '2022-12-24 14:00:00', '@Value': '49'}, {'@MeasurementDateGMT': '2022-12-24 15:00:00', '@Value': '45.2'}, {'@MeasurementDateGMT': '2022-12-24 16:00:00', '@Value': '53'}, {'@MeasurementDateGMT': '2022-12-24 17:00:00', '@Value': '44.4'}, {'@MeasurementDateGMT': '2022-12-24 18:00:00', '@Value': '38.7'}, {'@MeasurementDateGMT': '2022-12-24 19:00:00', '@Value': '17.6'}, {'@MeasurementDateGMT': '2022-12-24 20:00:00', '@Value': '14.4'}, {'@MeasurementDateGMT': '2022-12-24 21:00:00', '@Value': '12.2'}, {'@MeasurementDateGMT': '2022-12-24 22:00:00', '@Value': ''}]}}
I would like to get all of the "@Values" values from this dictionary, how would I go about doing it?