Skip to content

Commit

Permalink
fix(weather): handle missing API key or location in WeatherWidget
Browse files Browse the repository at this point in the history
Added error logging for cases where the API key or location is not provided, ensuring that users are informed of the missing parameters. Updated the default location to an empty string to prompt user input.
  • Loading branch information
amnweb committed Feb 10, 2025
1 parent dc1b1a2 commit 45af45c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/validation/widgets/yasb/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'label_alt': '0',
'update_interval': 3600,
'hide_decimal': False,
'location': 'London',
'location': '',
'api_key': '0',
'units': 'metric',
'show_alerts': False,
Expand Down
6 changes: 5 additions & 1 deletion src/core/widgets/yasb/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def __init__(
self._hide_decimal = hide_decimal
self._icons = icons
self._api_key = api_key if api_key != 'env' else os.getenv('YASB_WEATHER_API_KEY')
if not self._api_key or not self._location:
logging.error("API key or location is missing. Please provide a valid API key and location.")
return
self.api_url = f"http://api.weatherapi.com/v1/forecast.json?key={self._api_key}&q={urllib.parse.quote(self._location)}&days=3&aqi=no&alerts=yes"
self._units = units
self._show_alerts = show_alerts
self._padding = container_padding
Expand All @@ -50,7 +54,7 @@ def __init__(
self._animation = animation
self._weather_card = weather_card
self._icon_cache = dict()
self.api_url = f"http://api.weatherapi.com/v1/forecast.json?key={self._api_key}&q={urllib.parse.quote(self._location)}&days=3&aqi=no&alerts=yes"

# Construct container
self._widget_container_layout: QHBoxLayout = QHBoxLayout()
self._widget_container_layout.setSpacing(0)
Expand Down

0 comments on commit 45af45c

Please # to comment.