Fixing weather api issues

This commit is contained in:
Remy Moll
2020-12-10 11:20:00 +01:00
parent 7debff33ab
commit af839dd842
7 changed files with 53 additions and 31 deletions

View File

@@ -10,23 +10,21 @@ def show_weather(location):
try:
weather = requests.get(url,params=data).json()
print("WEATHER API CALLED")
categories = {"Clouds": ":cloud:", "Rain": ":cloud_with_rain:", "Thunderstorm": "thunder_cloud_rain", "Drizzle": ":droplet:", "Snow": ":cloud_snow:", "Clear": ":sun:", "Mist": "Mist", "Smoke": "Smoke", "Haze": "Haze", "Dust": "Dust", "Fog": "Fog", "Sand": "Sand", "Dust": "Dust", "Ash": "Ash", "Squall": "Squall", "Tornado": "Tornado",}
now = weather["current"]
message = "<b>Now:</b> " + categories[now["weather"][0]["main"]] + "\n"
message += ":thermometer: " + str(int(now["temp"])) + "°\n\n"
weather_days = weather["daily"]
for i, day in enumerate(weather_days):
if i == 0:
message += "<b>" + "Today" + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
else:
message += "<b>" + days[(today + i + 1) % 7] + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
message += ":thermometer: :fast_down_button: " + str(int(day["temp"]["min"])) + "° , :thermometer: :fast_up_button: " + str(int(day["temp"]["max"])) + "°\n\n"
except:
return "Query failed, it's my fault, I'm sorry :sad:"
categories = {"Clouds": ":cloud:", "Rain": ":cloud_with_rain:", "Thunderstorm": "thunder_cloud_rain", "Drizzle": ":droplet:", "Snow": ":cloud_snow:", "Clear": ":sun:", "Mist": "Mist", "Smoke": "Smoke", "Haze": "Haze", "Dust": "Dust", "Fog": "Fog", "Sand": "Sand", "Dust": "Dust", "Ash": "Ash", "Squall": "Squall", "Tornado": "Tornado",}
now = weather["current"]
message = "<b>Now:</b> " + categories[now["weather"][0]["main"]] + "\n"
message += ":thermometer: " + str(int(now["temp"])) + "°\n\n"
weather_days = weather["daily"]
for i, day in enumerate(weather_days):
if i == 0:
message += "<b>" + "Today" + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
else:
message += "<b>" + days[(today + i + 1) % 7] + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
message += ":thermometer: :fast_down_button: " + str(int(day["temp"]["min"])) + "° , :thermometer: :fast_up_button: " + str(int(day["temp"]["max"])) + "°\n\n"
return message