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?
ChatBot/ChatboxHLC.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
126 lines (113 sloc)
5 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
#Chatbox | |
from Check import checky, checkn, checkw #importing functions from check files | |
from weather import Weather, Unit ## requires "pip install weather-api" | |
greet = True #Greetings code | |
while greet == True: | |
name = "" | |
while name == "": | |
name = input("Hello what is your name? ") | |
if name != "": | |
print("Hello ",name) | |
else: | |
print("Please enter a name") | |
age = input("How old are you? ") | |
passAge = False | |
while passAge == False: | |
try: | |
age = int(age) | |
if age <=0 or age >= 110: | |
age = input("That's not possible, how old are you? ") | |
elif age < 20: | |
print("Wow, so young") | |
passAge = True | |
elif age == 20: | |
print("Wow same!!") | |
passAge = True | |
else: | |
diff = age - 20 | |
print("You're ", diff ," years older than me") | |
passAge = True | |
except ValueError: | |
age = input("Age is a number, how old are you? ") | |
passb = False | |
yn = input("So your name is "+ name.capitalize() +" and you're "+ str(age) +" years old? ") | |
while passb == False: | |
yn = yn.lower() | |
if checky(yn) == False and checkn(yn) == False: | |
yn = input("I don't understand. Is the information correct, yes or no? ") | |
elif checky(yn): | |
print("That's great!") | |
greet = False | |
passb = True | |
else: | |
print("Oh, let's start again then") | |
passb = True | |
feeling = input("How are you doing? ") #Ask about feelings | |
feeling = feeling.lower() | |
if feeling == "ok" or feeling == "good" or feeling == "fine" or feeling == "alright": | |
print("How boring") | |
elif feeling == "bad" or feeling == "terrible" or feeling == "sad" or feeling == "stressed": | |
print("Maybe it's because you're talking to a computer :D"); | |
elif feeling == "great" or feeling == "fantastic" or feeling == "brilliant" or feeling == "very good": | |
print("If talking to a computer is making you happy then you need to get out more"); | |
else: | |
print("I don't care") | |
talk = "" | |
while talk != "goodbye": #Main loop for code | |
talk = input("What would you like to talk about? ") | |
talk = talk.lower() | |
if "hello" in talk: #If hello is inputted | |
print ("hello....again") | |
elif "foot" in talk: #Talk about football | |
football = input("What football team do you support? ") | |
football = football.lower() | |
if "watford" in football: | |
print("Correct answer") | |
elif "arsenal" or "liverpool" or "manchester united" or "man u" or "tottenham" or "spurs" or "chelsea" in football: | |
print("Glory hunter") | |
elif "none" or "don\"t" in football: | |
print ("not a footabll fan?") | |
else: | |
print("Who?") | |
elif checkw(talk): #Talk about weather - uses api | |
valweather = False | |
#https://pypi.org/project/weather-api/ - template code | |
weather = Weather(unit=Unit.CELSIUS) | |
place = input("Which place do you want to know the weather for? ") | |
while valweather == False: | |
try: | |
location = weather.lookup_by_location(place) | |
# if location is None: | |
# print("Please enter a valid location") | |
# continue | |
condition = location.condition | |
forecasts = location.forecast | |
print("The weather in " + place + " is currently " +condition.text.lower()) | |
for forecast in forecasts: | |
print("The weather on " +forecast.date + " is "+ forecast.text.lower() + ". With highs of " + forecast.high + " degrees and lows of "+ forecast.low +" degrees") | |
valweather = True | |
except AttributeError: | |
place = input("Please enter a place ") | |
except KeyError: | |
place = input("Please enter a place ") | |
elif talk == "": #if nothing is is inputted | |
end = input("Do you not feel like talking? ") | |
if end == "yes": | |
print ("bye") | |
exit() #exit program | |
else: | |
"" | |
elif "film" in talk: #talk about films | |
film = input("What films have you seen recently? ") | |
film = film.lower() | |
if "star wars" or "force" in film: | |
print("RIP Han Solo") | |
else: | |
print("There is literally only one film I can talk about and that isn\"t it") | |
elif "me" in talk: #talk about me | |
print("I don\"t really care about you though") | |
elif "bye" in talk: #exiting program | |
print("seeya") | |
exit() | |
else: | |
print ("If your going to make up some rubbish then I will too, iasgfigaibrawskefb") #unknown input | |