Official documentation: http://powietrze.gios.gov.pl/pjp/content/api#
In [1]:
%matplotlib inline
In [2]:
import requests
from pandas.io.json import json_normalize
import pandas as pd
Getting all stations:
In [3]:
r = requests.get('http://api.gios.gov.pl/pjp-api/rest/station/findAll')
In [4]:
allStations = json_normalize(r.json())
In [5]:
print(allStations[allStations["city.name"] == u"Gdańsk"])
Lets see what we have in "AM5 Gdańsk Szadółki" which has id: 733
In [6]:
stationId = 733
In [7]:
r = requests.get('http://api.gios.gov.pl/pjp-api/rest/station/sensors/' + str(stationId))
In [8]:
sensors = json_normalize(r.json())
In [9]:
print(sensors)
Lets now see data about PM10 concentration - sensorId = 4727
In [10]:
sensorId = 4727
In [11]:
r = requests.get('http://api.gios.gov.pl/pjp-api/rest/data/getData/' + str(sensorId))
In [12]:
concentration = json_normalize(r.json())
In [13]:
concentrationFrame = pd.DataFrame()
In [14]:
concentrationFrame["dates"] = [d[u'date'] for d in concentration["values"].values.item()]
concentrationFrame["values"] = [d[u'value'] for d in concentration["values"].values.item()]
In [15]:
concentrationFrame.set_index(["dates"], inplace=True)
#concentrationFrame.sort_index(inplace=True)
# We cannot sort index, because it is not unique. There is 12 hours notation used, but without AM/PM distinction ;(
# But we can just reverse it until API will be fixed
concentrationFrame = concentrationFrame.iloc[::-1]
In [16]:
print(concentrationFrame)
In [17]:
concentrationFrame.plot(figsize=(15,5), grid=True)
Out[17]:
And overall air quality index for the same station
In [18]:
r = requests.get('http://api.gios.gov.pl/pjp-api/rest/aqindex/getIndex/' + str(stationId))
In [19]:
r.json()
Out[19]:
In [ ]: