diff --git a/README.md b/README.md index 7c293ea..4602a03 100644 --- a/README.md +++ b/README.md @@ -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. ---------------------------------------------------- @@ -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()** diff --git a/pirateweather/api.py b/pirateweather/api.py index caa007a..7bfd4a2 100644 --- a/pirateweather/api.py +++ b/pirateweather/api.py @@ -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. @@ -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: @@ -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 diff --git a/pirateweather/models.py b/pirateweather/models.py index 83e109b..f713cf0 100644 --- a/pirateweather/models.py +++ b/pirateweather/models.py @@ -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") @@ -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) @@ -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", []) ]