Skip to content

Commit

Permalink
Add helper FMI.fetch_stations() for fetching the available stations.
Browse files Browse the repository at this point in the history
  • Loading branch information
kipe committed Jun 17, 2022
1 parent 293e462 commit cd00ac1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ f = FMI()
print(f.observations(fmisid=101237))
```

### New in 1.2.0
Added a helper `FMI.fetch_stations()` for fetching the possible stations. For example:
```
>>> from fmi import FMI
>>> from pprint import pprint
>>> pprint([
... station
... for station in FMI.fetch_stations()
... if station['name'].startswith('Lappeenranta')
... ])
[{'fmisid': 101252,
'groups': ['sää'],
'height': 77,
'latitude': 61.2,
'longitude': 28.47,
'name': 'Lappeenranta Hiekkapakka',
'started': 2009,
'wmo': 2919},
{'fmisid': 101237,
'groups': ['sää'],
'height': 104,
'latitude': 61.04,
'longitude': 28.13,
'name': 'Lappeenranta lentoasema',
'started': 1950,
'wmo': 2958}]
```

Forecast icons
--------------

Expand Down
22 changes: 22 additions & 0 deletions fmi/fmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,25 @@ def forecast(self, model='hirlam', **params):
maxlocations=1,
klass=Forecast,
**params)

@staticmethod
def fetch_stations():
response = requests.get('https://cdn.fmi.fi/weather-observations/metadata/all-finnish-observation-stations.fi.json') # noqa: E501
response.raise_for_status()
return [
{
'fmisid': station.get('fmisid', None),
'wmo': station.get('wmo', None),
'name': station.get('name', ''),
'latitude': station.get('y', None),
'longitude': station.get('x', None),
'height': station.get('z', None),
'started': station.get('started', 1900),
'groups': [
x.strip()
for x in station.get('groups', '').split(',')
],
}
for station in response.json().get('items', [])
if station['ended'] is None
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='fmi_weather',
version='1.1.2',
version='1.2.0',
description='FMI weather data fetcher',
author='Kimmo Huoman',
author_email='kipenroskaposti@gmail.com',
Expand Down

0 comments on commit cd00ac1

Please sign in to comment.