<jupyter_start><jupyter_text>https://www.londonair.org.uk/LondonAir/API/<jupyter_code>import requests
import json
import pprint

def print_json(json_data):
    pprint.PrettyPrinter().pprint(json_data)<jupyter_output><empty_output><jupyter_text>Single site<jupyter_code>SiteCode = 'KT4'
url = 'http://api.erg.kcl.ac.uk/AirQuality/Hourly/MonitoringIndex/SiteCode={}/Json'.format(SiteCode)
url
response = requests.get(url).json()  # get the response object
print_json(response)
base = response['HourlyAirQualityIndex']['LocalAuthority']['Site']
base['@SiteName']
for species in base['species']:
    print('*****')
    print(species['@SpeciesName'])
    print(species['@AirQualityIndex'])
    print(species['@AirQualityBand'])<jupyter_output>*****
Nitrogen Dioxide
1
Low
*****
PM10 Particulate
1
Low<jupyter_text>All sites<jupyter_code>url = 'http://api.erg.kcl.ac.uk/AirQuality/Hourly/MonitoringIndex/GroupName=London/Json'
response = requests.get(url).json()  # get the response object
base = response['HourlyAirQualityIndex']['LocalAuthority']
print(len(base))   # 33 sites

for authority in base:
    print(authority['@LocalAuthorityName'])
print(len(base[2]['Site']))   # there are 8 sites
for site in base[2]['Site']:
    print(site['@SiteName'])
base[2]['Site'][0]
for species in base[2]['Site'][0]['Species']:
    print('******')
    print(species['@SpeciesDescription'])
    print(species['@AirQualityIndex'])
    print(species['@AirQualityBand'])<jupyter_output>******
Nitrogen Dioxide
1
Low
******
Ozone
2
Low
******
PM10 Particulate
1
Low<jupyter_text>Make a class<jupyter_code># Class will return dict of attributes of form

attributes = {'LocalAuthorityName': 'Kingston', 
              'SiteCode': 'KT4',
              'SiteName': 'Kingston upon thames',
              '@BulletinDate': '2017-07-04 03:00:00',              # Will be sensor state
              'species': [
        {'@AirQualityBand': 'Low',
         '@AirQualityIndex': '1',
         '@IndexSource': 'Trigger',
         '@SpeciesCode': 'PM10',
         '@SpeciesName': 'PM10 Particulate'}
    ]}<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17174119885823025, 'fraction_numerical': 0.018553758325404377, 'mean_word_length': 4.940677966101695, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '463650', 'license': 'MIT', 'n_tokens_mistral': 753, 'n_tokens_neox': 714, 'n_words': 127, 'path': 'Requests/London Air Quality 4-7-2017.ipynb', 'repo_name': 'afcarl/Useful-python', 'size': '2102'}