Skip to content

Commit 39a8f11

Browse files
committed
Add data set for accessing "daily" resolution
1 parent 9e6a4af commit 39a8f11

6 files changed

Lines changed: 345 additions & 34 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ in progress
99
- Naming things
1010
- Update knowledgebase, adjust some field names
1111
- Add some integration tests
12+
- Add data set for accessing "daily" resolution
1213

1314

1415
2020-05-30 0.12.1

README.rst

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ Synopsis
4545
Command line usage
4646
==================
4747

48+
Get all stations with ``daily`` resolution::
49+
50+
dwdweather stations --resolution=daily
51+
4852
Get all stations with ``hourly`` resolution (default)::
4953

50-
dwdweather stations
54+
dwdweather stations --resolution=hourly
5155

5256
Get all stations with ``10_minutes`` resolution::
5357

54-
dwdweather stations --resolution 10_minutes
58+
dwdweather stations --resolution=10_minutes
5559

5660
Get closest station (first argument is longitude, second is latitude)::
5761

@@ -77,6 +81,14 @@ Finally, to drop the cache database before performing any work, use the ``--rese
7781

7882
dwdweather stations --reset-cache
7983

84+
Choose dataset with ``daily`` resolution::
85+
86+
dwdweather weather 44 2020-06-01 --resolution=daily
87+
88+
Choose dataset with ``hourly`` resolution::
89+
90+
dwdweather weather 44 2020-06-01T08 --resolution=hourly
91+
8092
Choose dataset with ``10_minutes`` resolution::
8193

8294
dwdweather weather 2667 2019-06-01T15:20 --resolution=10_minutes
@@ -139,28 +151,25 @@ Licenses
139151

140152
Code license
141153
============
142-
Licensed under the MIT license. See file ``LICENSE`` for details.
154+
Licensed under the MIT license. See `LICENSE <https://github.com/panodata/dwdweather2/blob/master/LICENSE>`__ for details.
143155

144156
Data license
145157
============
146-
The DWD has information about their re-use policy in
158+
The DWD has information about their terms of use policy in
147159
`German <https://www.dwd.de/DE/service/copyright/copyright_node.html>`__
148160
and
149161
`English <https://www.dwd.de/EN/service/copyright/copyright_node.html>`__.
150162

151163

152-
******
153-
Status
154-
******
155-
This piece of software is in a very early stage. No test cases yet. Only
156-
tested with Python 3.6. Use at your own risk.
164+
*******************
165+
Project information
166+
*******************
157167

158168
Credits
159169
=======
160-
Thanks to `Marian Steinbach <https://github.com/marians>`__, `Philipp
161-
Klaus <https://github.com/pklaus>`__ and all people from
162-
`DWD <https://www.dwd.de/>`__.
170+
Thanks to `Marian Steinbach <https://github.com/marians>`__, all
171+
other contributors and the `DWD <https://www.dwd.de/>`__.
163172

164173
Changelog
165174
=========
166-
See file ``CHANGES.rst``.
175+
See file `CHANGES.rst <https://github.com/panodata/dwdweather2/blob/master/CHANGES.rst>`__.

dwdweather/client.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from urllib.parse import urlparse
88
from zipfile import ZipFile
99

10+
from requests import HTTPError
1011
from requests_cache import CachedSession
1112

1213
from dwdweather import __appname__ as APP_NAME
@@ -26,7 +27,7 @@ class DwdCdcClient:
2627

2728
def __init__(self, resolution, cache_path):
2829

29-
# Data set selector by resolution (houry, 10_minutes).
30+
# Data set selector by resolution (daily, hourly, 10_minutes).
3031
self.resolution = resolution
3132

3233
# HTTP client.
@@ -67,7 +68,14 @@ def setup_cache(self):
6768

6869
def get_resource_index(self, uri, extension):
6970
log.info(u'Requesting %s', uri)
70-
resource_list = fetch_html_file_list(uri, extension)
71+
try:
72+
resource_list = fetch_html_file_list(uri, extension)
73+
except HTTPError as ex:
74+
if ex.response.status_code == 404:
75+
#log.warning('Resource {} not found'.format(uri))
76+
resource_list = []
77+
else:
78+
raise
7179
return resource_list
7280

7381
def get_stations(self, categories):
@@ -77,11 +85,13 @@ def get_stations(self, categories):
7785
log.info("Loading station data from CDC")
7886
for category in categories:
7987
category_name = category["name"]
80-
if category_name == "solar" and self.resolution == "hourly":
88+
category_folder = category.get("folder", category_name)
89+
90+
if category_name == "solar" and self.resolution in ["daily", "hourly"]:
8191
# workaround - solar has no subdirs
82-
index_uri = u"%s/%s" % (self.uri, category_name)
92+
index_uri = u"%s/%s" % (self.uri, category_folder)
8393
else:
84-
index_uri = u"%s/%s/recent" % (self.uri, category_name)
94+
index_uri = u"%s/%s/recent" % (self.uri, category_folder)
8595

8696
try:
8797
resource_list = self.get_resource_index(index_uri, "txt")
@@ -104,6 +114,7 @@ def get_stations(self, categories):
104114
def get_measurements(self, station_id, category, timeranges):
105115

106116
category_name = category["name"]
117+
category_folder = category.get("folder", category_name)
107118

108119
def download_zip(uri):
109120
log.info("Fetching resource {}".format(uri))
@@ -144,7 +155,7 @@ def download_resource(uri):
144155
for thing in download_zip(uri):
145156
yield thing
146157

147-
if category_name == "solar" and self.resolution == "hourly":
158+
if category_name == "solar" and self.resolution in ["daily", "hourly"]:
148159
index_uri = "%s/%s" % (self.uri, category_name)
149160
resource_uri_effective = find_resource_file(
150161
index_uri, "_%05d_" % station_id
@@ -158,7 +169,7 @@ def download_resource(uri):
158169
if timerange == "historical":
159170
timerange_suffix = "hist"
160171

161-
index_uri = "%s/%s/%s" % (self.uri, category_name, timerange)
172+
index_uri = "%s/%s/%s" % (self.uri, category_folder, timerange)
162173
resource_uri_effective = find_resource_file(
163174
index_uri, "_%05d_" % station_id
164175
)

dwdweather/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, resolution="hourly", category_names=None, **kwargs):
5151
# Configure context
5252
# =================
5353

54-
# Data set selector by resolution (houry, 10_minutes).
54+
# Data set selector by resolution (daily, hourly, 10_minutes).
5555
self.resolution = resolution
5656

5757
# Categories of measurements.

0 commit comments

Comments
 (0)