Skip to content

Commit

Permalink
owm: streamline API calls
Browse files Browse the repository at this point in the history
Using `.format()` for some parameters and a `params` dict for others
seemed unnecessarily complicated.
  • Loading branch information
dgw authored and RustyBower committed Jan 27, 2023
1 parent ce4304e commit f7370a6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions sopel_modules/weather/providers/weather/openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
from datetime import datetime


def openweathermap_forecast(bot, latitude, longitude, location):
url = 'https://api.openweathermap.org/data/2.5/onecall?appid={}&lat={}&lon={}'.format(
bot.config.weather.weather_api_key,
latitude,
longitude
)
API_ENDPOINT = 'https://api.openweathermap.org/data/2.5/onecall'


def openweathermap_forecast(bot, latitude, longitude, location):
params = {
'appid': bot.config.weather.weather_api_key,
'lat': latitude,
'lon': longitude,
'exclude': 'current,minutely,hourly',
'units': 'metric'
}
try:
r = requests.get(url, params=params)
r = requests.get(API_ENDPOINT, params=params)
except:
raise Exception("An Error Occurred. Check Logs For More Information.")
data = r.json()
Expand All @@ -35,18 +35,15 @@ def openweathermap_forecast(bot, latitude, longitude, location):


def openweathermap_weather(bot, latitude, longitude, location):
url = 'https://api.openweathermap.org/data/2.5/onecall?appid={}&lat={}&lon={}'.format(
bot.config.weather.weather_api_key,
latitude,
longitude
)

params = {
'exclude': 'minutely,hourly,daily',
'appid': bot.config.weather.weather_api_key,
'lat': latitude,
'lon': longitude,
'exclude': 'current,minutely,hourly',
'units': 'metric'
}
try:
r = requests.get(url, params=params)
r = requests.get(API_ENDPOINT, params=params)
except:
raise Exception("An Error Occurred. Check Logs For More Information.")
data = r.json()
Expand Down

0 comments on commit f7370a6

Please sign in to comment.