Compare commits
2 Commits
404126cc70
...
6afeec78e9
Author | SHA1 | Date | |
---|---|---|---|
6afeec78e9 | |||
f0ff184902 |
26
weather.py
26
weather.py
@ -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']
|
||||
|
Loading…
Reference in New Issue
Block a user