Removed dead code, changed WeatherInterface and implemented forecasts into Owm weather, but did not test it
This commit is contained in:
parent
65f36f6039
commit
26bdceb22e
4 changed files with 25 additions and 11 deletions
|
@ -66,8 +66,8 @@ def main ():
|
||||||
raise ImportError("choosen_design must be valid (" + choosen_design + ")")
|
raise ImportError("choosen_design must be valid (" + choosen_design + ")")
|
||||||
|
|
||||||
debug.print_line("Fetching weather information from open weather map")
|
debug.print_line("Fetching weather information from open weather map")
|
||||||
owm = OwmForecasts.OwmForecasts(api_key)
|
owm = OwmForecasts.OwmForecasts(location, api_key)
|
||||||
design.add_weather(OwmForecasts.OwmForecasts(api_key))
|
design.add_weather(owm)
|
||||||
|
|
||||||
debug.print_line('Fetching events from your calendar')
|
debug.print_line('Fetching events from your calendar')
|
||||||
events_cal = IcalEvents.IcalEvents(ical_urls)
|
events_cal = IcalEvents.IcalEvents(ical_urls)
|
||||||
|
|
|
@ -6,9 +6,11 @@ from settings import units
|
||||||
|
|
||||||
class OwmForecasts (WeatherInterface):
|
class OwmForecasts (WeatherInterface):
|
||||||
"""Fetches weather through the Openweathermap-api."""
|
"""Fetches weather through the Openweathermap-api."""
|
||||||
def __init__ (self, api_key):
|
def __init__ (self, location, api_key, paid_api=False):
|
||||||
self.api = pyowm.OWM(api_key)
|
subscription = "pro" if paid_api else None
|
||||||
|
self.api = pyowm.OWM(api_key, subscription_type=subscription)
|
||||||
self.units = units
|
self.units = units
|
||||||
|
self.location = location
|
||||||
|
|
||||||
def is_available (self):
|
def is_available (self):
|
||||||
try:
|
try:
|
||||||
|
@ -16,16 +18,28 @@ class OwmForecasts (WeatherInterface):
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_today_forecast (self, location):
|
def get_today_forecast (self, location=None):
|
||||||
if self.is_available() is False:
|
if self.is_available() is False:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
location = self.location if location is None else location
|
||||||
|
|
||||||
observation = self.api.weather_at_place(location)
|
observation = self.api.weather_at_place(location)
|
||||||
weather = observation.get_weather()
|
weather = observation.get_weather()
|
||||||
|
|
||||||
return self.__get_forecast_from_weather__(weather, location=location)
|
return self.__get_forecast_from_weather__(weather, location=location)
|
||||||
|
|
||||||
def get_forecast_in_days (self, offset_by_days, location):
|
def get_forecast_in_days (self, offset_by_days, location=None):
|
||||||
|
if self.is_available() is False:
|
||||||
|
return None
|
||||||
|
|
||||||
|
location = self.location if location is None else location
|
||||||
|
try:
|
||||||
|
forecast = self.api.daily_forecast(location, limit=offset_by_days)
|
||||||
|
target_weather = forecast.get_forecast().get_weathers()[-1]
|
||||||
|
|
||||||
|
return self.__get_forecast_from_weather__(target_weather, location=location)
|
||||||
|
except: # only allowed for paied membership
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __get_forecast_from_weather__ (self, weather, location):
|
def __get_forecast_from_weather__ (self, weather, location):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from DesignEntity import DesignEntity
|
from DesignEntity import DesignEntity
|
||||||
from Assets import *
|
from Assets import *
|
||||||
from TextDesign import TextDesign
|
from TextDesign import TextDesign
|
||||||
from settings import units, hours, location
|
from settings import units, hours
|
||||||
|
|
||||||
wiconplace = (0, 0)
|
wiconplace = (0, 0)
|
||||||
tempplace = (0.779, 0)
|
tempplace = (0.779, 0)
|
||||||
|
@ -22,7 +22,7 @@ class WeatherHeaderDesign (DesignEntity):
|
||||||
self.__render_missing_connection__()
|
self.__render_missing_connection__()
|
||||||
return
|
return
|
||||||
|
|
||||||
cur_weather = self.__weather__.get_today_forecast(location)
|
cur_weather = self.__weather__.get_today_forecast()
|
||||||
|
|
||||||
temperature = cur_weather.air_temperature + " " + self.__get_unit__(("°C", "°F"))
|
temperature = cur_weather.air_temperature + " " + self.__get_unit__(("°C", "°F"))
|
||||||
windspeed = cur_weather.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
|
windspeed = cur_weather.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
|
||||||
|
|
|
@ -2,8 +2,8 @@ from DataSourceInterface import DataSourceInterface
|
||||||
|
|
||||||
class WeatherInterface (DataSourceInterface):
|
class WeatherInterface (DataSourceInterface):
|
||||||
"""Interface for fetching and processing weather forecast information."""
|
"""Interface for fetching and processing weather forecast information."""
|
||||||
def get_forecast_in_days (self, offset_by_days, location):
|
def get_forecast_in_days (self, offset_by_days, location=None):
|
||||||
raise NotImplementedError("Functions needs to be implemented")
|
raise NotImplementedError("Functions needs to be implemented")
|
||||||
|
|
||||||
def get_today_forecast (self, location):
|
def get_today_forecast (self, location=None):
|
||||||
raise NotImplementedError("Functions needs to be implemented")
|
raise NotImplementedError("Functions needs to be implemented")
|
Loading…
Reference in a new issue