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?
6A-Chatbot/weather.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (30 sloc)
1.12 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 pyowm, reminderTextProcessing | |
def equalInArray(array, string): #made by Ben G | |
for i in range(0,len(array)): | |
if array[i].lower() == string.lower(): | |
return True | |
return False | |
def detPlace(command): #made by Ben G | |
wordsplit = command.split() | |
locDetermine = ["at","in","for"] | |
for i in range(0,len(wordsplit)): | |
if equalInArray(locDetermine, reminderTextProcessing.puncRemove(wordsplit[i].lower())) and i + 1 < len(wordsplit): | |
return wordsplit[i + 1] | |
return None | |
def weather(command): | |
owm = pyowm.OWM( | |
'3e00d7a3b5f712c576e77953d91643f3') | |
city = detPlace(command) | |
string = "" | |
if city != None: | |
try: | |
loc = owm.weather_manager().weather_at_place(reminderTextProcessing.puncRemove(city.lower())) | |
weather = loc.weather | |
# temperature | |
temp = weather.temperature(unit='celsius') | |
for key, val in temp.items(): | |
string = string + "\n" + (f'{key} => {val}') | |
return string | |
except: | |
return "Invalid location" | |
return "You need to type in a location" |