Skip to content

Commit 8d7a69c

Browse files
Inital support for V2.8 features (#141)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 15b87b9 commit 8d7a69c

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Parameters:
7474
- **version** - (optional) Defaults to `1`. If set to `2` the API will return fields that were not part of the Dark Sky API.
7575
- **icon** - (optional) Defaults to `darksky`. If set to `pirate` the API will return icons which aren't apart of the default Dark Sky icon set.
7676
- **extraVars** - (optional) Is used to add additional parameters to the API response. The only extra parameter at the moment is `stationPressure` but more may be added in the future.
77+
- **include** - (optional) Is used to add additional data blocks to the API response. The only accepted parameter at the moment is `day_night_forecast` but `aqi` may be added in the future.
7778
- **callback** - (optional) Pass a function to be used as a callback. If used, load_forecast() will use an asynchronous HTTP call and **will not return the forecast object directly**, instead it will be passed to the callback function. Make sure it can accept it.
7879

7980
----------------------------------------------------
@@ -110,6 +111,8 @@ The **Forecast** object, it contains both weather data and the HTTP response fro
110111
- Returns a PirateWeatherDataBlock object
111112
- **hourly()**
112113
- Returns a PirateWeatherDataBlock object
114+
- **day_night()**
115+
- Returns a PirateWeatherDataBlock object
113116
- **daily()**
114117
- Returns a PirateWeatherDataBlock object
115118
- **flags()**

pirateweather/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def load_forecast(
2020
version=1,
2121
icon="darksky",
2222
extraVars=None,
23+
include=None,
2324
):
2425
"""Build the request url and loads some or all of the needed json depending on lazy is True.
2526
@@ -39,6 +40,7 @@ def load_forecast(
3940
version: If set to 2 the API will return fields that were not part of the Dark Sky API.
4041
icon: If set to pirate the API will return icons which aren't apart of the default Dark Sky icon set
4142
extraVars: Is used to add additional parameters to the API response.
43+
include: Is used to add additional data blocks to the API response.
4244
"""
4345

4446
if time is None:
@@ -47,6 +49,8 @@ def load_forecast(
4749
url += f"&extend={extend}"
4850
if extraVars:
4951
url += f"&extraVars={extraVars}"
52+
if include:
53+
url += f"&include={include}"
5054
else:
5155
url_time = time.replace(
5256
microsecond=0

pirateweather/models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def hourly(self):
3838
"""Return the hourly weather data block."""
3939
return self._pirateweather_data("hourly")
4040

41+
def day_night(self):
42+
"""Return the day_night weather data block."""
43+
return self._pirateweather_data("day_night")
44+
4145
def daily(self):
4246
"""Return the daily weather data block."""
4347
return self._pirateweather_data("daily")
@@ -55,8 +59,8 @@ def alerts(self):
5559
return self._alerts
5660

5761
def _pirateweather_data(self, key):
58-
"""Fetch and return specific weather data (currently, minutely, hourly, daily)."""
59-
keys = ["minutely", "currently", "hourly", "daily", "flags"]
62+
"""Fetch and return specific weather data (currently, minutely, hourly, daily, flags and day_night)."""
63+
keys = ["minutely", "currently", "hourly", "daily", "flags", "day_night"]
6064
try:
6165
if key not in self.json:
6266
keys.remove(key)
@@ -86,8 +90,8 @@ class PirateWeatherDataBlock(UnicodeMixin):
8690
def __init__(self, d=None):
8791
"""Initialize the data block with summary and icon information."""
8892
d = d or {}
89-
self.summary = d.get("summary")
90-
self.icon = d.get("icon")
93+
self.summary = d.get("summary", None)
94+
self.icon = d.get("icon", None)
9195
self.data = [
9296
PirateWeatherDataPoint(datapoint) for datapoint in d.get("data", [])
9397
]

0 commit comments

Comments
 (0)