Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Parameters:
- **version** - (optional) Defaults to `1`. If set to `2` the API will return fields that were not part of the Dark Sky API.
- **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.
- **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.
- **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.
- **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.

----------------------------------------------------
Expand Down Expand Up @@ -110,6 +111,8 @@ The **Forecast** object, it contains both weather data and the HTTP response fro
- Returns a PirateWeatherDataBlock object
- **hourly()**
- Returns a PirateWeatherDataBlock object
- **day_night()**
- Returns a PirateWeatherDataBlock object
- **daily()**
- Returns a PirateWeatherDataBlock object
- **flags()**
Expand Down
4 changes: 4 additions & 0 deletions pirateweather/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def load_forecast(
version=1,
icon="darksky",
extraVars=None,
include=None,
):
"""Build the request url and loads some or all of the needed json depending on lazy is True.

Expand All @@ -39,6 +40,7 @@ def load_forecast(
version: If set to 2 the API will return fields that were not part of the Dark Sky API.
icon: If set to pirate the API will return icons which aren't apart of the default Dark Sky icon set
extraVars: Is used to add additional parameters to the API response.
include: Is used to add additional data blocks to the API response.
"""

if time is None:
Expand All @@ -47,6 +49,8 @@ def load_forecast(
url += f"&extend={extend}"
if extraVars:
url += f"&extraVars={extraVars}"
if include:
url += f"&include={include}"
else:
url_time = time.replace(
microsecond=0
Expand Down
12 changes: 8 additions & 4 deletions pirateweather/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def hourly(self):
"""Return the hourly weather data block."""
return self._pirateweather_data("hourly")

def day_night(self):
"""Return the day_night weather data block."""
return self._pirateweather_data("day_night")

def daily(self):
"""Return the daily weather data block."""
return self._pirateweather_data("daily")
Expand All @@ -55,8 +59,8 @@ def alerts(self):
return self._alerts

def _pirateweather_data(self, key):
"""Fetch and return specific weather data (currently, minutely, hourly, daily)."""
keys = ["minutely", "currently", "hourly", "daily", "flags"]
"""Fetch and return specific weather data (currently, minutely, hourly, daily, flags and day_night)."""
keys = ["minutely", "currently", "hourly", "daily", "flags", "day_night"]
try:
if key not in self.json:
keys.remove(key)
Expand Down Expand Up @@ -86,8 +90,8 @@ class PirateWeatherDataBlock(UnicodeMixin):
def __init__(self, d=None):
"""Initialize the data block with summary and icon information."""
d = d or {}
self.summary = d.get("summary")
self.icon = d.get("icon")
self.summary = d.get("summary", None)
self.icon = d.get("icon", None)
self.data = [
PirateWeatherDataPoint(datapoint) for datapoint in d.get("data", [])
]
Expand Down
Loading