Compare commits
No commits in common. "6afeec78e9a432561a2ae55dabd12aa27a300aab" and "404126cc70cc1bce2d93c630d792105662de3ee6" have entirely different histories.
6afeec78e9
...
404126cc70
1 changed files with 3 additions and 23 deletions
26
weather.py
26
weather.py
|
@ -5,26 +5,6 @@ import datetime
|
||||||
import dateutil.parser as dp
|
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:
|
class WeatherApi:
|
||||||
|
|
||||||
def __init__(self, nick):
|
def __init__(self, nick):
|
||||||
|
@ -99,10 +79,10 @@ class WeatherApi:
|
||||||
|
|
||||||
def get_current_conditions(self, nick, location=None, units=None):
|
def get_current_conditions(self, nick, location=None, units=None):
|
||||||
user_preferences = self.get_user_preferences(nick)
|
user_preferences = self.get_user_preferences(nick)
|
||||||
units = user_preferences[nick]['units'] if nick in user_preferences.keys() else 'metric'
|
units = user_preferences[nick]['units']
|
||||||
|
|
||||||
if not location:
|
if not location:
|
||||||
location = user_preferences[nick]['location'] if user_preferences[nick]['location'] else raise NoDefaultLocation()
|
location = user_preferences[nick]['location']
|
||||||
|
|
||||||
# URL for current conditions
|
# URL for current conditions
|
||||||
current_url = f"{self.weather_api_url}/current.json?key={self.api_key}&q={location}&qai=no"
|
current_url = f"{self.weather_api_url}/current.json?key={self.api_key}&q={location}&qai=no"
|
||||||
|
@ -127,7 +107,7 @@ class WeatherApi:
|
||||||
|
|
||||||
def get_forecast(self, nick, location=None, days=5, units=None):
|
def get_forecast(self, nick, location=None, days=5, units=None):
|
||||||
user_preferences = self.get_user_preferences(nick) if not units else 'metric'
|
user_preferences = self.get_user_preferences(nick) if not units else 'metric'
|
||||||
units = user_preferences[nick]['units'] if nick in user_preferences.keys() else 'metric'
|
units = user_preferences[nick]['units']
|
||||||
|
|
||||||
if not location:
|
if not location:
|
||||||
location = user_preferences[nick]['location']
|
location = user_preferences[nick]['location']
|
||||||
|
|
Loading…
Add table
Reference in a new issue