Code
Code
import asyncio
import datetime
import random
TOKEN = "NTAzODQ0OTc4NDM1NDI0MjU2.DsH8wQ.qCmyacFwrPmqXw5wWElOdCiWOIk"
client = discord.Client()
CDT = datetime.datetime.now()
#location = geocoder.ip("me")
weather = Weather(unit=Unit.CELSIUS)
#weatherLookp = weather.lookup_by_latlng(location.lat, location.lng)
#weatherLookp = weather.lookup_by_location("")
#condation = weatherLookp.condition
content = message.content
channel = message.channel
author = message.author
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello, how can I help...'.format(message)
await client.send_message(message.channel, msg)
showerImg = "hello.jpg"
await client.send_file(channel, showerImg)
if content.lower() == "weather":
reply = "I dont know where you live, To know the weather tell me
where you live?".format(message)
await client.send_message(message.channel, reply)
# check the city name in userMessage and send the weather report
for value in location_city:
if ("forecast" or "weather forecast") in content.lower():
forcaste = weatherTable(value)
await client.send_message(message.channel,forcaste )
break
if ("weahter" and value.lower()) in content.lower():
image = ""
weather = weatherLookup(value)
temp = something(value)
msg = "its "+ weather + " in " + value
for k,v in conditions.items():
if k in msg:
image = v
break
await client.send_message(message.channel, msg)
def weatherTable(content):
"""
input: content as string
return: weather inforamtion tempreture, condition as a table
"""
weatherReport = PrettyTable()
weatherReport.field_names = ["conditions", "Date", "High", "Low"]
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location(content)
forecasts = location.forecast
for forecast in forecasts:
weatherReport.add_row([forecast.text,forecast.date,forecast.high +
"°",forecast.low+"°"])
weatherReport.add_row([" ", " ", " ", " "])
weatherReport.add_row([" ", " ", " ", " "])
return weatherReport
def Jokes(file_name):
"""
input: file name eg, text.txt
retun list with jokes
"""
file = open(file_name,'r')
jokes = []
for value in file:
value = value.strip('\n')
#dic[value] = dic.get(value)
jokes.append(value)
file.close()
return jokes
def weatherLookup(area):
"""
Input: Name of city
Output: weather condition depending on the location/city.
"""
weather = Weather(unit=Unit.CELSIUS)
weatherLookp = weather.lookup_by_location(area)
condition = weatherLookp.condition
return condition.text
@client.event
async def on_ready():
print(client.user.name)
print(client.user.id)
print("Is Ready & Logged On!")
await client.send_message(client.get_channel(id= '503843931771895810'),
'I am alive!')
client.run(TOKEN)