Compare commits

...

2 Commits

View File

@ -5,6 +5,26 @@ import datetime
import dateutil.parser as dp
class NoDefaultLocation(Exception):
def __init__(self, message=None):
default_message = "No default location set"
if not message:
message = default_message
super().__init__(message)
class NoLocationSpecified(Exception):
def __init__(self, message=None):
default_message = "No location specified"
if not message:
message = default_message
super().__init__(message)
class WeatherApi:
def __init__(self, nick):
@ -79,10 +99,10 @@ class WeatherApi:
def get_current_conditions(self, nick, location=None, units=None):
user_preferences = self.get_user_preferences(nick)
units = user_preferences[nick]['units']
units = user_preferences[nick]['units'] if nick in user_preferences.keys() else 'metric'
if not location:
location = user_preferences[nick]['location']
location = user_preferences[nick]['location'] if user_preferences[nick]['location'] else raise NoDefaultLocation()
# URL for current conditions
current_url = f"{self.weather_api_url}/current.json?key={self.api_key}&q={location}&qai=no"
@ -107,7 +127,7 @@ class WeatherApi:
def get_forecast(self, nick, location=None, days=5, units=None):
user_preferences = self.get_user_preferences(nick) if not units else 'metric'
units = user_preferences[nick]['units']
units = user_preferences[nick]['units'] if nick in user_preferences.keys() else 'metric'
if not location:
location = user_preferences[nick]['location']