Skip to content
Permalink
7273913e97
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
352 lines (299 sloc) 13.1 KB
#!/usr/bin/env python
"""Provides a chatbot for the residents and students of Coventry.
Provides information for new Coventry students and residents to help them find their feet in the city.
"""
from josh.weather import getWeather #Imports Josh's weather module
from josh.covNews import covNews #Imports Josh's Coventry News module
from josh.covEvents import covEvents #imports Josh's Coventry Events module
from josh.covAnnounce import covAnnounce #Imports Josh's CU moodle announcements module
from josh.lostID import lostID #Imports Josh's lostID module.
from josh.phoenixPoints import phoenixPoints, phoenixPointsSearch #Imports phoenixPoint locator
from josh.futureLets import futureLets, futureLetsSearch, roomDetails #Imports Josh's FuturLets module
from josh.uniBuildings import uniBuildings, uniBuildingsSearch #Imports Josh's Cov Uni Building info
from josh.telegram import * #Imports Telegram API functions for Telegram bot integration.
from abdullah.medicalCentres import medicalCentres #Imports Abdullah's medical centre module
from abdullah.primeModule import primeModule #imports Abdullah's prime module.
from ilya.errorModule import Error #Imports Ilya's script to Google search userInput if it is not recognized by any functions
from ilya.SocietyModule import LookForSocietyNew #Imports Ilya's module for searching for a society
from ilya.SocietyModule import LookForSocietyFinal #Imports Ilya's module for searching for a society
from ilya.conversationIlya import Languages #Imports Ilya's script to look for a society for user's ethnicity
from ilya.conversationIlya import Mood #Imports Ilya's script to get user's current mood
from ilya.conversationIlya import Movie #Imports Ilya's script to suggest a list of movies based on user's current mood
from ilya.examSearch import SearchForExams #Imports Ilya's script to tell user about upcoming exams for their course
from dragos.food import food #Imports Dragos' food module.
from dragos.events import clubs
from dragos.supermarkets import supermarket
from dragos.fargo import fargo
from kris.currency2 import currencyConverter
from time import sleep #Needed for intervals between Telegram messages sending.
__author__ = "Joshua Lewis-Handley, Dragos Dudu, Abdullah Ejrf, Ilya Tsykunov, Kristaps Ruments"
__credits__ = ["Joshua Lewis-Handley", "Dragos Dudu", "Abdullah Ejrf",
"Ilya Tsykunov", "Kristaps Ruments"]
__version__ = "2.1"
__maintainer__ = "Authors"
__email__ = "handley7@uni.coventry.ac.uk"
__status__ = "Development"
#Initialise a variable for user input and 1 which stores the previous user input.
userInput=""
oldText=""
#Variables to store information about the user. Ilya
userInputName = "None" #Their name. Ilya
userInputCourse = "None" #The course they are taking. Ilya
userInputMood = "None" #Their current mood. Ilya
userInputLanguages = "None" #Other languages they speak. Ilya
#Loop runs until message "exit" is received
while True: #Josh
#previous userInput is stored in old text. Josh
oldText=userInput
#Updates from Telegram are fetched. Josh
updates=get_updates()
#the last message and ID from telegram is fetched and stored. Josh
userInput,chat=get_last_chat_id_and_text(updates)
userInput.lower() #Josh
triesLeft = 2 #Ilya
commandError = False #Ilya
if(userInputName == "None"): #Ilya
response = "covBot: I'm covBot, what is your name? "
send_message(response,chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
userInputName = userInput
if(userInputCourse == "None"): #Ilya
response = "covBot: What course are you studying at Coventry? "
send_message(response,chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
userInputCourse = userInput
if(userInputMood == "None"): #Ilya
response = "covBot: How are you today? "
send_message(response,chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
userInputMood = Mood(userInput)
if(userInputLanguages == "None"): #Ilya
response = "covBot: Do you speak any languages other than English? "
send_message(response,chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
userInputLanguages = Languages(userInput)
#String checks are only ran if a new message is received. Else, it continuously checks until a new message is received.
if oldText != userInput: #Josh
if "weather" in userInput: #Josh
commandError=False #Ilya
response=getWeather() #Josh - weather function ran and stored.
send_message(response,chat) #Josh - weather output is sent to Telegram using send_message function from telegram.
elif "news" in userInput: #Josh
commandError=False # Ilya
r1,r2,r3,r4,r5=covNews() #5 articles fetched and stored. Josh
#Articles sent as invidividual messages, with 2 second intervals to avoid spam filtering from Telegram.
send_message(r1,chat)
sleep(2)
send_message(r2,chat)
sleep(2)
send_message(r3,chat)
sleep(2)
send_message(r4,chat)
sleep(2)
send_message(r5,chat)
elif "events" in userInput: #josh
commandError=False
r1,r2,r3,r4,r5=covEvents()
print(r1,r2,r3,r4,r5)
send_message(r1,chat)
sleep(2)
send_message(r2,chat)
sleep(2)
send_message(r3,chat)
sleep(2)
send_message(r4,chat)
sleep(2)
send_message(r5,chat)
elif "announcements" in userInput: #josh
commandError=False
r1,r2,r3,r4,r5=covAnnounce() #5 articles fetched and stored. Josh
#Articles sent as invidividual messages, with 2 second intervals to avoid spam filtering from Telegram.
send_message(r1,chat)
sleep(2)
send_message(r2,chat)
sleep(2)
send_message(r3,chat)
sleep(2)
send_message(r4,chat)
sleep(2)
send_message(r5,chat)
elif "building" in userInput: #josh
commandError=False
r1, r2 = uniBuildings()
send_message(r1, chat)
sleep(2)
send_message(r2, chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
response=uniBuildingsSearch(userInput)
send_message(response, chat)
elif "lost" in userInput: #josh
commandError=False
r1,r2,r3=lostID()
send_message(r1,chat)
sleep(2)
send_message(r2,chat)
sleep(2)
send_message(r3,chat)
elif "medical" in userInput: #Josh
commandError=False
medicalCentres()
elif "prime" in userInput: #josh
commandError=False
primeModule()
elif "phoenix" in userInput: #josh
commandError=False
r1,r2=phoenixPoints()
send_message(r1, chat)
sleep(2)
send_message(r2, chat)
oldText=userInput
#Check that new message has been received/question has been answered
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
#Once answered, function to search for phoenix point is ran.
response=phoenixPointsSearch(userInput)
#Result is sent as a message.
send_message(response, chat)
elif "accomodation" in userInput: #josh
commandError=False
r1,r2,r3=futureLets()
send_message(r1,chat)
sleep(2)
send_message(r2,chat)
sleep(2)
send_message(r3,chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
r1,r2=futureLetsSearch(userInput)
send_message(r1, chat)
sleep(2)
send_message(r2,chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
r1,r2,r3,r4 = roomDetails(userInput)
send_message(r1,chat)
sleep(2)
send_message(r2,chat)
sleep(2)
send_message(r3,chat)
sleep(2)
send_message(r4,chat)
elif ("society" in userInput or "societies" in userInput): #ilya
commandError = False
response = "covBot: Please start by typing in the type of society you would like to learn about, you can enter a type to see all of the associated societies "
send_message(response, chat)
response = LookForSocietyNew(userInput, True, False)
sleep(2)
send_message(response, chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
response, chosenSocietyType = LookForSocietyNew(userInput, False, True)
sleep(2)
send_message(response, chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
response = LookForSocietyFinal(userInput, chosenSocietyType)
sleep(2)
send_message(response, chat)
elif("exam" in userInput): #ilya
commandError = False
response = SearchForExams(userInputCourse)
send_message(response, chat)
elif("movie" in userInput or "film" in userInput or "watch" in userInput): #ilya
commandError=False
response = Movie(userInputMood)
send_message(response, chat)
elif ("food" in userInput):
commandError=False
food()
elif ("supermarket" in userInput):
commandError=False
supermarket()
elif ("club" in userInput):
commandError=False
clubs()
elif ("convert money" in userInput) or ("convert currency" in userInput) or ("exchange money" in userInput) or ("exchange currency" in userInput): #Kris
commandError=False
available_currencies = "covBot: Here are your available currencies: British pound, US dollar, Indian rupee, Japanese yen, Chinese yuan, Russian ruble and Romanian leu."
send_message(available_currencies, chat)
oldText=userInput
while True:
userInput, chat = get_last_chat_id_and_text(get_updates())
if oldText==userInput:
pass
else:
break
convertedVal = currencyConverter(userInput)
response = "covBot: The converted value is "+convertedVal
send_message(response, chat)
elif "exit" in userInput: #Josh #NOTE: Keep me at the bottom.
commandError=False
break
#else: #Ilya
#commandError = True
#if(commandError == True): #ilya
#Error(commandError, triesLeft)
#Team process:
#1. ENSURE FUNCTIONS ONLY RETURN STRINGS AS A VARIABLE TO BE SENT AS A MESSAGE. CAN'T PRINT. (if time is an issue - don't worry)
#2. import your individual modules as individual python files below mine.
#3. comment that they are yours and which module.
#4. Add elif statement to make the chatbot run your code. ensure they don't clash.
#5. Comment that you added the 'elif' block.
#6. Test - if no issues, tell the rest of the team and push your moudule. and this updated file to GitHub.
#
#IMPORTANT NOTICE:
#Ensure the string statements in your modules start with `covBot: `