Skip to content

Commit

Permalink
Merge pull request #28 from jacobtomlinson/rc-0.4.1
Browse files Browse the repository at this point in the history
Release 0.4.1
  • Loading branch information
jacobtomlinson authored Jan 4, 2017
2 parents dcb9730 + d444a52 commit 18d9bed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion datapoint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Datapoint API to retrieve Met Office data"""

__version__ = "0.4.0"
__version__ = "0.4.1"
__author__ = "Jacob Tomlinson"
__author_email__ = "[email protected]"

Expand Down
16 changes: 8 additions & 8 deletions datapoint/regions/RegionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

from datapoint.Site import Site
from datapoint.regions.region_names import REGION_NAMES

REGIONS_BASE_URL = 'http://datapoint.metoffice.gov.uk/public/data/txt/wxfcs/regionalforecast/json'


class RegionManager(object):
'''
Datapoint Manager for national and regional text forecasts
Datapoint Manager for national and regional text forecasts
'''
def __init__(self, api_key, base_url=None):
self.api_key = api_key
Expand All @@ -30,18 +30,18 @@ def call_api(self, path, **kwargs):
'''
if 'key' not in kwargs:
kwargs['key'] = self.api_key
req = requests.get('{}{}'.format(self.base_url, path), params=kwargs)
req = requests.get('{0}{1}'.format(self.base_url, path), params=kwargs)

if req.status_code != requests.codes.ok:
req.raise_for_status()

return req.json()

def get_all_regions(self):
'''
Request a list of regions from Datapoint. Returns each Region
as a Site object. Regions rarely change, so we cache the response
for one hour to minimise requests to API.
Request a list of regions from Datapoint. Returns each Region
as a Site object. Regions rarely change, so we cache the response
for one hour to minimise requests to API.
'''
if (time() - self.regions_last_update) < self.regions_update_time:
return self.regions_last_request
Expand All @@ -63,4 +63,4 @@ def get_raw_forecast(self, region_id):
'''
Request unformatted forecast for a specific region_id.
'''
return self.call_api('/{}'.format(region_id))
return self.call_api('/{0}'.format(region_id))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from distutils.core import setup

setup(name='datapoint',
version='0.4.0',
version='0.4.1',
install_requires=[
"requests >= 2.3.0",
"appdirs",
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/regions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def test_call_api(self):

def test_get_all_regions(self):
all_regions = self.regions.get_all_regions()
sample_region = filter(lambda x: x.id == '515', all_regions)[0]
sample_region = next(
region for region in all_regions
if region.id == '515')
assert (sample_region.name == 'UK')
assert (sample_region.region == 'uk')

def test_get_raw_forecast(self):
sample_region = self.regions.get_all_regions()[0]
response = self.regions.get_raw_forecast(
Expand All @@ -38,4 +40,4 @@ def test_get_raw_forecast(self):
forecast_periods = response['FcstPeriods']['Period']
forecast_ids = [period['id'] for period in forecast_periods]
expected_ids = ['day1to2', 'day3to5', 'day6to15', 'day16to30']
assert (forecast_ids == expected_ids)
assert (forecast_ids == expected_ids)

0 comments on commit 18d9bed

Please sign in to comment.