Permalink
Cannot retrieve contributors at this time
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?
chatBotProject/LocationWeather.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 lines (57 sloc)
3.24 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
import geocoder | |
from predicthq import Client | |
import datetime | |
class LocationAndWeather: | |
def __init__(self, client): | |
self.client = client | |
@commands.command(name = "bot", | |
description="format: ?bot, gives bots hosting location", | |
brief="tells the user where the bot is currently being ran from", | |
pass_context=True) | |
async def botLocate(self, ctx): | |
g = geocoder.ip('me') | |
await self.client.say("```The bot is currently being hosted in: {}```".format(g.city)) | |
@commands.command(name = "locate", | |
description="format: ?locate [landmark name]', gives landmarks address", | |
brief="tells the user the location of a place they search for", | |
pass_context=True) | |
async def searchPlaceAddress(self, ctx, place): | |
g = geocoder.bing(place, key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') | |
await self.client.say("```The location is {}```".format(g.address)) | |
@commands.command(name = "coord", | |
description="format: ?coord [landmark name]', gives landmarks lat and lng", | |
brief="tells the user the latlng of a place they search for", | |
pass_context=True) | |
async def searchPlaceLatlng(self, ctx, place): | |
g = geocoder.bing(place, key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') | |
await self.client.say("```The location is {}```".format(g.latlng)) | |
@commands.command(name = "event", | |
description="format: ?event [city] [type of event]', gives landmarks address", | |
brief="tells the user events happening around the location they enter", | |
pass_context=True) | |
async def searchEvents(self, ctx, place, eventType): | |
output = [] | |
text = "" | |
phq = Client(access_token="Ds4t0V0Z71WuXvOyBsm2IFXDZaQxgh") | |
g = geocoder.bing(place, key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') | |
eventLocation = str('10km@' + str(g.lat) + ',' + str(g.lng)) | |
for event in phq.events.search(q=eventType, within=eventLocation): | |
if event.rank > 0: | |
now = datetime.datetime.now() | |
eventReverseLnglat = event.location | |
eventLng = eventReverseLnglat[1] | |
eventLat = eventReverseLnglat[0] | |
eventLnglat = str("[" + str(eventLng) + "," + str(eventLat) + "]") | |
h = geocoder.bing(eventLnglat, method='reverse', key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') | |
if int(now.day) < int(event.start.strftime('%d')): | |
output.append("Event details: {} - {} - {}".format(event.start.strftime('%d-%m-%Y'), event.title, event.category)) | |
output.append("Event address: {}".format(h.address)) | |
output.append("Event score : {}/ 100".format(event.rank)) | |
output.append("") | |
for eventdetails in output: | |
text = text + eventdetails + "\n" | |
await self.client.say("```{}```".format(text)) | |
def setup(client): | |
client.add_cog(LocationAndWeather(client)) |