Skip to content

Commit 305446f

Browse files
author
Emlyn Price
authored
Merge pull request #170 from EJEP/tidy_id_and_api_key
Tidy id and api key
2 parents 0620481 + fa58dbd commit 305446f

File tree

21 files changed

+42
-51
lines changed

21 files changed

+42
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
+ Remove deprecated `new_old` and `future_old` functions.
88
+ Add `__str__` functions to `Timestep`, `Element`, `Day`, `Site`
99
+ Add element to `Forecast` to track if forecast is daily or 3 hourly
10+
+ Change `id` variable in `Forecast`, `Observation`, `Site` to `location_id`.
11+
+ Change `id` variable in `Element` to `field_code`.
1012

1113
## [0.9.8] - 2020-07-03
1214

1315
+ Remove f-string in test
14-
16+
1517
## [0.9.7] - 2020-07-03
1618

1719
+ Bugfix for `get_observation_sites`
@@ -141,4 +143,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
141143

142144
## [0.1] - 2014-07-16
143145

144-
+ Initial commit and license.
146+
+ Initial commit and license.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ conn = datapoint.connection(api_key="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
4646
site = conn.get_nearest_forecast_site(51.500728, -0.124626)
4747

4848
# Get a forecast for my nearest site with 3 hourly timesteps
49-
forecast = conn.get_forecast_for_site(site.id, "3hourly")
49+
forecast = conn.get_forecast_for_site(site.location_id, "3hourly")
5050

5151
# Get the current timestep from the forecast
5252
current_timestep = forecast.now()

datapoint/Day.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
class Day():
2-
def __init__(self, api_key=""):
3-
self.api_key = api_key
4-
2+
def __init__(self):
53
self.date = None
64
self.timesteps = []
75

datapoint/Element.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Element():
2-
def __init__(self, id=None, value=None, units=None):
2+
def __init__(self, field_code=None, value=None, units=None):
33

4-
self.id = id
4+
self.field_code = field_code
55
self.value = value
66
self.units = units
77

datapoint/Forecast.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33

44

55
class Forecast():
6-
def __init__(self, api_key="", frequency=""):
7-
self.api_key = api_key
8-
6+
def __init__(self, frequency=""):
97
self.frequency = frequency
108
self.data_date = None
119
self.continent = None
1210
self.country = None
1311
self.name = None
1412
self.longitude = None
1513
self.latitude = None
16-
self.id = None
14+
self.location_id = None
1715
self.elevation = None
1816
self.days = []
1917

datapoint/Manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def get_forecast_sites(self):
247247
for jsoned in data['Locations']['Location']:
248248
site = Site()
249249
site.name = jsoned['name']
250-
site.id = jsoned['id']
250+
site.location_id = jsoned['id']
251251
site.latitude = jsoned['latitude']
252252
site.longitude = jsoned['longitude']
253253

@@ -359,7 +359,7 @@ def get_forecast_for_site(self, site_id, frequency="daily"):
359359
forecast.latitude = data['SiteRep']['DV']['Location']['lat']
360360

361361
if 'i' in data['SiteRep']['DV']['Location']:
362-
forecast.id = data['SiteRep']['DV']['Location']['i']
362+
forecast.location_id = data['SiteRep']['DV']['Location']['i']
363363

364364
if 'elevation' in data['SiteRep']['DV']['Location']:
365365
forecast.elevation = data['SiteRep']['DV']['Location']['elevation']
@@ -467,7 +467,7 @@ def get_observation_sites(self):
467467
for jsoned in data['Locations']['Location']:
468468
site = Site()
469469
site.name = jsoned['name']
470-
site.id = jsoned['id']
470+
site.location_id = jsoned['id']
471471
site.latitude = jsoned['latitude']
472472
site.longitude = jsoned['longitude']
473473

@@ -553,7 +553,7 @@ def get_observations_for_site(self, site_id, frequency='hourly'):
553553
observation.latitude = data['SiteRep']['DV']['Location']['lat']
554554

555555
if 'i' in data['SiteRep']['DV']['Location']:
556-
observation.id = data['SiteRep']['DV']['Location']['i']
556+
observation.location_id = data['SiteRep']['DV']['Location']['i']
557557

558558
if 'elevation' in data['SiteRep']['DV']['Location']:
559559
observation.elevation = data['SiteRep']['DV']['Location']['elevation']

datapoint/Observation.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
import datetime
2-
31
class Observation():
4-
def __init__(self, api_key=""):
5-
self.api_key = api_key
6-
2+
def __init__(self):
73
self.data_date = None
84
self.continent = None
95
self.country = None
106
self.name = None
117
self.longitude = None
128
self.latitude = None
13-
self.id = None
9+
self.location_id = None
1410
self.elevation = None
1511
# Stores a list of observations in days
1612
self.days = []
1713

1814
def now(self):
1915
"""
20-
Return the final timestep available. This is the most recent observation.
16+
Return the final timestep available. This is the most recent
17+
observation.
2118
"""
2219

2320
return self.days[-1].timesteps[-1]

datapoint/Site.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class Site():
2-
def __init__(self, api_key=""):
3-
self.api_key = api_key
4-
2+
def __init__(self):
53
self.name = None
6-
self.id = None
4+
self.location_id = None
75
self.elevation = None
86
self.latitude = None
97
self.longitude = None

datapoint/Timestep.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from .Element import Element
22

33
class Timestep():
4-
def __init__(self, api_key=""):
5-
self.api_key = api_key
6-
4+
def __init__(self):
75
self.name = None
86
self.date = None
97
self.weather = None

datapoint/regions/RegionManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_all_regions(self):
5050
regions = []
5151
for location in response['Locations']['Location']:
5252
region = Site()
53-
region.id = location['@id']
53+
region.location_id = location['@id']
5454
region.region = location['@name']
5555
region.name = REGION_NAMES[location['@name']]
5656
regions.append(region)

0 commit comments

Comments
 (0)