Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ dmypy.json
todo.txt
.vscode/launch.json
storage/prefixes.json
storage/weathertoken.txt
.vscode/settings.json
20 changes: 9 additions & 11 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from discord.ext import commands
import math
import requests
import dotenv
from dotenv import load_dotenv
load_dotenv()
weathertoken = os.getenv('WEATHER_TOKEN')
import dotenv

# Cog class:
class Utility(commands.Cog):
Expand Down Expand Up @@ -96,10 +93,11 @@ async def desc(self, ctx, *, cname):
# Weather command
@commands.command(name="weather")
async def _weather(self, ctx, city_name):
# TODO #2 Fix weather command
"""Get weather information about a location. Usage: ?weather <location>"""
with open("storage/weathertoken.txt") as tokenweather:
weathertoken = tokenweather.readlines(1)
base_url = "http://api.weatherapi.com/v1/current.json?"
complete_url = base_url + "key=" + weathertoken + "&q=" + city_name
complete_url = base_url + "key=f44ceda5450e4c16be585450200805" + "&q=" + str(city_name)
try:
response = requests.get(complete_url)
except BaseException:
Expand All @@ -112,15 +110,15 @@ async def _weather(self, ctx, city_name):
current_temperature = str(int(weather["temp_c"])) + "°C"
current_pressure = str(weather["pressure_mb"])[-3:] + "mBar"
current_humidity = str(weather["humidity"]) + "%"
image = "https:" + condition["icon"]
weather_timezone = location["localtime"]
weather_location = location["name"]
weather_description = "Description: " + condition["text"]
image = "https:" + str(condition["icon"])
weather_timezone = str(location["localtime"])
weather_location = str(location["name"])
weather_description = "Description: " + str(condition["text"])
weather_wind_kph = str(weather["wind_kph"])
weather_wind_dir = str(weather["wind_dir"])

weatherembed = discord.Embed(title="Weather for " + weather_location,color=0x7ac5c9)
weatherembed.set_author(name=f"{client.user.name}",icon_url=client.user.avatar_url)
weatherembed.set_author(name=f"{self.client.user.name}",icon_url=self.client.user.avatar_url)
weatherembed.set_footer(text="https://weatherapi.com")
weatherembed.add_field(name="Temperature:", value=current_temperature)
weatherembed.add_field(name="Pressure:", value=current_pressure)
Expand Down