Пример #1
0
r = requests.get(config.AIRLY_FIND_ALL_STATION_URL, headers=headers, timeout=5)
resonse = r.json()

for station in resonse:
    r = requests.get(config.AIRLY_GET_STATION_STATUS_URL + str(station['id']),
                     headers=headers,
                     timeout=5)

    station_details = r.json()
    history = station_details['history']

    for status in history:
        measurements = status['measurements']
        normalized_measurements = {}
        normalized_measurements['id'] = station['id']
        normalized_measurements['vendor'] = 'AIRLY'

        normalized_measurements[
            'pm2_5'] = measurements['pm25'] if 'pm25' in measurements else None
        normalized_measurements[
            'pm10'] = measurements['pm10'] if 'pm10' in measurements else None
        normalized_measurements['temperature'] = measurements[
            'temperature'] if 'temperature' in measurements else None
        normalized_measurements['date'] = datetime.strptime(
            status['fromDateTime'],
            '%Y-%m-%dT%H:%M:%SZ').strftime("%Y-%m-%d %H:%M:%S")

        producer.send('monitoring', normalized_measurements)
        print("Send info about station {}".format(station['id']))
        time.sleep(2)
Пример #2
0
import requests
from api import config, producer

headers = {'apikey': config.AIRLY_TOKEN}
r = requests.get(config.AQICN_FIND_ALL_STATION_URL, headers=headers, timeout=5)
response = r.json()

if r.status_code == 200:
    for station in response['data']:
        url = config.AQICN_GET_STATION_STATUS_URL
        url = url.replace("LAT", str(station['lat']))
        url = url.replace('LNG', str(station['lon']))

        r = requests.get(url)
        station_details = r.json()

        normalized_station = {}
        normalized_station['vendor'] = 'AQICN'
        normalized_station['id'] = station['uid']
        normalized_station['station_name'] = station_details['data'][
            'attributions'][1]['name']
        normalized_station['lng'] = station['lon'] + 0.0004
        normalized_station['lat'] = station['lat'] + 0.0004
        normalized_station['city'] = "Krakow"
        normalized_station['street'] = station_details['data']['city']['name']

        producer.send('station', normalized_station)
        print("Send info about station {}".format(normalized_station['id']))