Skip to content

Commit

Permalink
v1.02: nighttime indicatir
Browse files Browse the repository at this point in the history
  • Loading branch information
mjj4791 committed Dec 21, 2019
1 parent 4e9fab7 commit a09eac5
Show file tree
Hide file tree
Showing 6 changed files with 1,480 additions and 62 deletions.
21 changes: 17 additions & 4 deletions CHANGLOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ Changelog
All notable changes to this project will be documented in this file.
Changes that did not make it into a new release are marked with [unreleased].

[1.0.2] - 2019-12-15
""""""""""""""""""""
**changed**

- derive condition from icon url and no longer using condition text
- updated tests
- lowered loglevel of missng weather-data elements to debug

**new**

- added nighttime indicator in condition section; derived from icon url


[1.0.1] - 2019-06-10
""""""""""""""""""""
**changed**
Expand All @@ -12,11 +25,11 @@ Changes that did not make it into a new release are marked with [unreleased].
- updated calculation of forcasted temperature and rain (json)
- New sensor types:

- added (json only): barometerfcnamenl
- added forecast for (json only):
- added (json only): barometerfcnamenl
- added forecast for (json only):

- windspeed (estimated using windforce)
- windazimuth (estimated using winddirection)
- windspeed (estimated using windforce)
- windazimuth (estimated using winddirection)


[1.0.0] - 2019-03-02
Expand Down
58 changes: 49 additions & 9 deletions buienradar/buienradar_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
MESSAGE,
MIN_RAIN,
MIN_TEMP,
NIGHTTIME,
PRECIPITATION,
PRECIPITATION_FORECAST,
PRESSURE,
Expand Down Expand Up @@ -390,9 +391,18 @@ def __parse_loc_data(loc_data, result):
sens_data = loc_data[value]
if key == CONDITION:
# update weather symbol & status text
desc = loc_data[__WEATHERDESCRIPTION]
result[DATA][CONDITION] = __cond_from_desc(desc)
# desc = loc_data[__WEATHERDESCRIPTION]
# result[DATA][CONDITION] = __cond_from_desc(desc)
#
# test clear-->sunny vs clear-->clear-night
# loc_data[__ICONURL] =
# "https://www.buienradar.nl/resources/images/icons/weather/30x30/a.png"
# loc_data[__ICONURL] =
# "https://www.buienradar.nl/resources/images/icons/weather/30x30/aa.png"
result[DATA][CONDITION] = __cond_from_image(
loc_data[__ICONURL])
result[DATA][CONDITION][IMAGE] = loc_data[__ICONURL]

continue
if key == STATIONNAME:
result[DATA][key] = __getStationName(loc_data[__STATIONNAME],
Expand All @@ -404,11 +414,11 @@ def __parse_loc_data(loc_data, result):
else:
result[DATA][key] = sens_data
except KeyError:
if result[MESSAGE] is None:
result[MESSAGE] = "Missing key(s) in br data: "
result[MESSAGE] += "%s " % value
log.warning("Data element with key='%s' "
"not loaded from br data!", key)
# if result[MESSAGE] is None:
# result[MESSAGE] = "Missing key(s) in br data: "
# result[MESSAGE] += "%s " % value
log.debug("Data element with key='%s' "
"not loaded from br data!", key)
result[SUCCESS] = True
return result

Expand All @@ -418,10 +428,15 @@ def __parse_fc_data(fc_data):
fc = []
for day in fc_data:
fcdata = {
CONDITION: __cond_from_desc(
# CONDITION: __cond_from_desc(
# __get_str(
# day,
# __WEATHERDESCRIPTION)
# ),
CONDITION: __cond_from_image(
__get_str(
day,
__WEATHERDESCRIPTION)
__ICONURL)
),
TEMPERATURE: __get_avr_float(day, __MAXTEMPERATUREMIN,
__MAXTEMPERATUREMAX),
Expand All @@ -443,6 +458,8 @@ def __parse_fc_data(fc_data):
WINDAZIMUTH: __get_windazimuth(__get_str(day, __WINDDIRECTION)),
DATETIME: __to_localdatetime(__get_str(day, __DAY)),
}
# fc never is about nighttime:
fcdata[CONDITION][NIGHTTIME] = False
fcdata[CONDITION][IMAGE] = day[__ICONURL]

fc.append(fcdata)
Expand Down Expand Up @@ -583,6 +600,29 @@ def __cond_from_desc(desc):
return None


def __cond_from_image(image):
"""Get the condition from the image url."""
# the image url should be something like: http://somehost/somefolder/cc.png
# or http://somehost/somefolder/c.png if there is not url,
# or the length is too small, we cannot determine the condition.
if image is None or len(image) < 6:
return None
# __BRCONDITIONS = { 'code': 'conditon', 'detailed', 'exact', 'exact_nl'}
code = image[-5:-4]
night = False
if image[-6:-5] == code:
night = True
if code in __BRCONDITIONS:
return {CONDCODE: code,
CONDITION: __BRCONDITIONS[code][0],
DETAILED: __BRCONDITIONS[code][1],
EXACT: __BRCONDITIONS[code][2],
EXACTNL: __BRCONDITIONS[code][3],
NIGHTTIME: night
}
return None


def __select_nearest_ws(jsondata, latitude, longitude):
"""Select the nearest weatherstation."""
log.debug("__select_nearest_ws: latitude: %s, longitude: %s",
Expand Down
1 change: 1 addition & 0 deletions buienradar/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
IMAGE = 'image'
IRRADIANCE = 'irradiance'
MEASURED = 'measured'
NIGHTTIME = 'night'
PRECIPITATION = 'precipitation'
PRECIPITATION_FORECAST = 'precipitation_forecast'
PRESSURE = 'pressure'
Expand Down
Loading

0 comments on commit a09eac5

Please sign in to comment.