Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import discord
import time
import requests
async def weather(client,message):
'''Code extracted and editted from: https://pypi.org/project/weather-api/ '''
''' weather-api 1.0.6 '''
'''Return real time weather to users. Need Internet access!!! '''
#version1
from weather import Weather, Unit
weather = Weather(unit=Unit.CELSIUS)
lookup = weather.lookup(560743)
condition = lookup.condition
msg="It is "+((condition.text)).lower()+" today."
await client.send_message(message.channel, msg)
await client.send_message(message.channel, "Specific weather details: ")
#version2
#weather = Weather(unit=Unit.CELSIUS)
#location = weather.lookup_by_location('dublin')
#condition = location.condition
#print(condition.text)
while True:
try:
weather = Weather(unit=Unit.CELSIUS)
async client.send_message(message.channel,"Which place's weather do you want me to tell you? ")
@client.event
place=message.content
location = weather.lookup_by_location(place.strip())
forecasts = location.forecast
except:
await client.send_message(message.channel, "Invalid location!")
else:
for forecast in forecasts:
msg=forecast.date+" will be "+((forecast.text).lower()).strip(),"."
await client.send_message(message.channel, msg)
msg=forecast.date+":"+forecast.low+"℃ to "+forecast.high+"℃."
await client.send_message(message.channel, msg)
msg="On this day in "+place.strip()+", you should \t"
await client.send_message(message.channel,msg)
if float(forecast.low)>25 or float(forecast.high)>30:
msg=msg+"drink more water and beware of heat stroke."
elif float(forecast.low)<0 or float(forecast.high)<13:
msg=msg+"wear more clothes before outing. Beware of cold temperature otherwise you'll get a cold."
else:
msg=msg+"do nothing but enjoy your day, because this is a normal day."
await client.edit_message(message.channel,msg)
break
'''Extracted code ends.'''