Skip to content
Permalink
master
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
"""
To do
Add a system ot merge key phrases DONE
Add a way to find a location
Remove all punctuation from the question DONE
Auto generate the phrases based on tags
Clean up code, rename variables to better names
"""
# Imports .stem submodule from Natural Language toolkit
from nltk.stem import WordNetLemmatizer
import csv
import time
from uk_covid19 import Cov19API
from datetime import date
import wikipedia
import random
# welcomes the user with a greeting message and gives the an overall need to know information about coronavirus
def welcome_message():
welcome_message = input("Enter Your Name:")
print("Hello " + welcome_message + ", welcome, I am Covid-Bot.")
print("I am here to help with any information you may need about COVID-19 commonly known as coronavirus.")
time.sleep(1.0)
print("How may I be of service today?")
def wikicontent():
print("Here is a wikipedia article on covid-19")
wiki = wikipedia.page(
"coronavirus") # this gets the coronavirus article from the wikipedia webpage, https://stackoverflow.com/questions/53804643/how-can-i-get-a-wikipedia-articles-text-using-python-3-with-beautiful-soup
text = wiki.content
print(text)
# Removes punctuation from a string
def randomHello():
myRand = random.random()
if myRand < 0.33:
print("Hello")
elif 0.33 <= myRand <= 0.66:
print("Hi")
else:
print("Hey")
def removePunct(string):
punctuation = [".", ",", "-", "/", "!", ";"]
for punct in punctuation:
if punct == "-" or punct == "/":
string = string.replace(punct, " ")
# Creats a list of punctuation characters punctuation = [".",",","-","/","!","",";"] #Cycles through each punctuation character, and checks if that piece of puncuation is in the string.If it is it removes every character of that type
for punct in punctuation:
while punct in string:
string = string.replace(punct, "")
# print(string, punct)
# Write code to add a space before each question mark (?)
string = string.replace("?", " ?")
return string
###################################################################################################################
###################################################################################################################
# Chris
def botHelp():
print(
"You can ask me about infection and death rates in different locations in the UK! Make sure you include the location with correct spelling!")
print(
"If you would like to know the infection or death rates for a specific date make sure you use the words 'custom' and 'date'")
print(
"If you want to learn more about COVID-19 you can use the 'more information' keyword to get a brief information of the virus!")
print("I was created to give you information about COVID-19, but I am still a chatbot! Try me!")
print("If you want to exit the program, please use Ctrl+C for the Console terminal")
# Reads postcode districts.csv and turns that data into a list of lists https://www.youtube.com/watch?v=q5uM4VKywbA&ab_channel=CoreySchafer
def locationsGenerator():
with open('locations.csv',
'r') as csv_file: # Postcode districts from https://www.doogal.co.uk/postcodedownloads.php
csv_reader = csv.reader(csv_file)
next(csv_reader)
locations = []
for line in csv_reader:
newline = []
for entity in line:
entity = entity.lower()
newline.append(entity)
locations.append(newline)
return locations
# Takes tags as an input, and returns a phrases list
def phrasesGenerator(tags):
phrases = []
for tag in tags:
for marker in tags[tag]:
if " " in marker:
phrases.append(marker)
return phrases
# Inputs the question, and merges all of the key phrases in that string, as indicated by the phrases list
# 2 variables (listOfStrings and string) because having one would interfere with the for loop
def phraseMerger(listOfStrings, phrases):
# Turns the list of strings into a single string
string = " ".join(listOfStrings)
toAdd = []
# Cycles through each phrase, and checks if the phrase is in the string. If it is remove it from the string, and add it to the toAdd list
for phrase in phrases:
if phrase in string:
toAdd.append(phrase)
# Turns the string back into a list of strings
listOfStrings = string.split()
# Add on the toAdd list to the list of strings
if len(toAdd) > 0:
listOfStrings = listOfStrings + toAdd
return listOfStrings
def findLocations(locations, question, meaning):
# Cycles through each word in the question list, and each postcode locations. If there is a match add the postcode to meaning.
for word in question:
for row in locations:
# Check to see if the word is as long or longer than the postcode being tested
if len(word) >= len(row[0]):
newWord = ''
# Makes a variable equal to the length of the postocde being tested, starting from character 0
for i in range(len(row[0])):
newWord = newWord + word[i]
# Checks to see if the new variable is identical to the postcode being tested. If it is add it to the meaning list
if newWord == row[0]:
meaning.append("location " + newWord)
meaning.append("location code " + row[5])
meaning.append("main location " + row[2])
meaning.append("location provided")
# Checks for a match in the town/area collumn. If there is a match add the town/area and the region to meaning
places = row[1].split(", ")
for place in places:
if word == place and ("location " + place) not in meaning:
meaning.append("location " + word)
meaning.append("location code " + row[5])
meaning.append("main location " + row[2])
meaning.append("location provided")
# Checks for a match in the region collumn. If there is, add the region to the meaning
if word == row[2] and ("location " + row[5]) not in meaning:
meaning.append("location code " + row[5])
meaning.append("main location " + row[2])
meaning.append("location provided")
return meaning
def understand(question, tags, phrases, locations):
meaning = []
# Makes everything lowercase
question = question.lower()
# Removes all punctuation
question = removePunct(question)
# Splits Question Into a list of words
question = question.split()
# Lemmatizes each word
newQuestion = []
for word in question:
word = WordNetLemmatizer().lemmatize(word) # Replace this line
newQuestion.append(word)
question = newQuestion
# Merges key phrases in the question
question = phraseMerger(question, phrases)
# Cycles through each word in the question list, and each tag in the tags dict, and each marker in each tag list. This checks to see if a marker is in the question. If it is add the corresponding tag to the meaning list
for word in question:
for tag in tags:
for marker in tags[tag]:
if word == marker and tag not in meaning:
meaning.append(tag)
# Find locations
meaning = meaning + findLocations(locations, question, meaning)
# Removes repeats
meaning = list(dict.fromkeys(meaning))
return meaning
def tip():
tips = [
"Random Tip: If you would like to know the infection rate or death rate for a specifc date, include the words 'custom date' in your input",
"Random Tip: If you think you might be infected with Covid-19 you can ask me about any symptoms",
"Random Tip: If you are struggling with your inputs, just use the '/help' command"
]
print(random.choice(tips))
# Funciton that gives death rates and infection rates given a location
def ratesToday(meaning, tags, phrases,
locations): # https://coronavirus.data.gov.uk/details/developers-guide#structure-metrics https://publichealthengland.github.io/coronavirus-dashboard-api-python-sdk/pages/examples/general_use.html#instantiation
# Picks out the location from the meaning list
for element in meaning:
if element[0:13] == "main location":
areaName = element[14:len(element)]
areaName = areaName.capitalize()
areaName = "areaName=" + areaName
# Constructs the filters parameter to input into the API
fil = ['areaType=ltla']
fil.append(areaName)
# fil.append("date="+ date.today().strftime("%Y-%m-%d")) #https://www.programiz.com/python-programming/datetime/current-datetime
# fil.append("date=2020-11-19")
# Constructs the structure papameter to input into the API
cases_and_deaths = {
"date": "date",
"areaName": "areaName",
"newCases": "newCasesByPublishDate",
"cumCases": "cumCasesByPublishDate",
"newDeaths": "newDeaths28DaysByPublishDate",
"cumDeaths": "cumDeaths28DaysByPublishDate"
}
# Inputs parameters into API and retrives data
api = Cov19API(filters=fil, structure=cases_and_deaths)
locationData = api.get_json()
data = locationData['data']
# If the API returns no data, it instead inputs the area code and retrives the data
if len(data) == 0:
for element in meaning:
if element[0:13] == "location code":
areaCode = element[14:len(element)]
areaCode = areaCode.capitalize()
areaCode = "areaCode=" + areaCode
fil = ['areaType=ltla']
fil.append(areaCode)
api = Cov19API(filters=fil, structure=cases_and_deaths)
locationData = api.get_json()
data = locationData['data']
# If the API still doesn't return any data return to the main code
if len(data) == 0:
print("Sorry I am afraid I cannot find that location")
return
# Extracts the data dictionary from the data list and calls it data
data = data[0]
# Presents the data in a user friendly manner
if 'infection' in meaning and 'death' in meaning:
print("As of", data['date'], "there have been", data['newCases'], "new cases, and", data['cumCases'],
"total cases in the area of", data['areaName'] + ".")
print("There have been", data['newDeaths'], "new deaths, and", data['cumDeaths'], "total deaths in the area of",
data['areaName'] + ".")
elif 'infection' in meaning:
print("As of", data['date'], "there have been", data['newCases'], "new cases, and", data['cumCases'],
"total cases in the area of", data['areaName'] + ".")
print("I can also tell you about the death rates in", data['areaName'])
response = input("Would you like to see the death rates?\n")
# Uses the understand function to decipher the users input
responseMeaning = understand(response, tags, phrases, locations)
if 'yes' in responseMeaning:
print("As of", data['date'], "there have been", data['newDeaths'], "new deaths, and", data['cumDeaths'],
"total deaths in the area of", data['areaName'] + ".")
elif 'death' in meaning:
print("As of", data['date'], "there have been", data['newDeaths'], "new deaths, and", data['cumDeaths'],
"total deaths in the area of", data['areaName'] + ".")
print("I can also tell you about the infection rates in", data['areaName'])
response = input("Would you like to see the infection rates?\n")
responseMeaning = understand(response, tags, phrases, locations)
if 'yes' in responseMeaning:
print("As of", data['date'], "there have been", data['newCases'], "new cases, and", data['cumCases'],
"total cases in the area of", data['areaName'] + ".")
print("What else can I help you with?")
def ratesCustom(tags, phrases, locations):
print(
"You have chosen to input a specific date. Please be aware that government data may not be as up-to-date as you would like, so I may not be able to provide data for you chosen date")
print("Because I am a silly bot I am quite bad at decifering your language. You will need to help me out")
rateType = input("Would you like to know the infection rate or death rate?\n")
rateTypeMeaning = understand(rateType, tags, phrases, locations)
if "death" not in rateTypeMeaning and "infection" not in rateTypeMeaning:
print("That is not a valid input. If you wish to try again use the word 'custom' in your input")
return
selectedDate = input("Which date would you like to know about? Please use this format <YYYY-mm-dd>\n")
if len(selectedDate) != 10:
print("That is not a valid input. If you wish to try again use the word 'custom' in your input")
return
location = input("And which location?\n")
locationMeaning = understand(location, tags, phrases, locations)
if "location provided" not in locationMeaning:
print("That is not a valid input. If you wish to try again use the word 'custom' in your input")
return
for element in locationMeaning:
if element[0:13] == "main location":
areaName = element[14:len(element)]
areaName = areaName.capitalize()
areaName = "areaName=" + areaName
fil = ['areaType=ltla']
fil.append(areaName)
fil.append("date=" + selectedDate)
cases_and_deaths = {
"date": "date",
"areaName": "areaName",
"newCases": "newCasesByPublishDate",
"cumCases": "cumCasesByPublishDate",
"newDeaths": "newDeaths28DaysByPublishDate",
"cumDeaths": "cumDeaths28DaysByPublishDate"
}
api = Cov19API(filters=fil, structure=cases_and_deaths)
locationData = api.get_json()
data = locationData['data']
if len(data) == 0:
for element in locationMeaning:
if element[0:13] == "location code":
areaCode = element[14:len(element)]
areaCode = areaCode.capitalize()
areaCode = "areaCode=" + areaCode
fil = ['areaType=ltla']
fil.append(areaCode)
fil.append("date=" + selectedDate)
api = Cov19API(filters=fil, structure=cases_and_deaths)
locationData = api.get_json()
data = locationData['data']
data = data[0]
if len(data) == 0:
print("Sorry. I could not retrive any data based on your inputs. You will have to refine your inputs")
return
if "infection" in rateTypeMeaning and "death" in rateTypeMeaning:
print("As of", data['date'], "there were", data['newCases'], "new cases, and there were", data['cumCases'],
"total cases in the area of", data['areaName'] + ".")
print("There were", data['newDeaths'], "new deaths, and there were", data['cumDeaths'],
"total deaths in the area of", data['areaName'] + ".")
elif "infection" in rateTypeMeaning:
print("As of", data['date'], "there were", data['newCases'], "new cases, and there were", data['cumCases'],
"total cases in the area of", data['areaName'] + ".")
elif "death" in rateTypeMeaning:
print("As of", data['date'], "there were", data['newDeaths'], "new deaths, and there were", data['cumDeaths'],
"total deaths in the area of", data['areaName'] + ".")
print("What else can I help you with?")
# Asks a series of questions from a flowchart based on https://111.nhs.uk/covid-19 and gives a result (results don't replace the need to consult a doctor)
def diagnosis():
print("Which of the following bothers you the most?")
print("1. Cough")
print("2. High temperature with no other symptoms")
print("3. Loss or change to your smell or taste")
print("4. Cold or flu symptoms")
print("5. Breathlessness")
print("6. Tiredness")
print("7. None of the above")
diag_choice = input("")
if diag_choice == "1" or diag_choice == "2" or diag_choice == "3" or diag_choice == "4" or diag_choice == "5" or diag_choice == "6":
# print("You chose: symptom") Idea to make a symptom list and include the descripton on this line
print("I'll need to ask you some questions about your symptoms.")
print("You won't get a diagnosis, but you will find out what steps to take next.")
ext_diagnosis()
elif diag_choice == "7":
print("You chose: '7. None of the above'")
print("It's unlikely you have COVID-19")
print("If you feel worst phone your GP or NHS 111 immediately and consider isolating")
# All further questions of diagnosis function
def ext_diagnosis():
def P999_1():
print("RESULT: Phone 999.")
def P999_2():
print("RESULT: Phone 999, you have COVID-19 symptoms.")
def P999_3():
print("RESULT: Phone 111 or 999 for serious issues.")
def AE():
print("RESULT: Unlikely to have COVID-19, go to the nearest A&E.")
def GP():
print("RESULT: Contact your GP as soon as possible.")
def breath_hard():
print("Are you so ill that you've stopped doing all of your usual daily activities?")
print("1. Yes - I've stopped doing everything I usually do")
print("2. I feel ill but can do some of my usual activities")
print("3. No - I feel well enough to do most of my usual daily activities")
ext_dq = input("")
if ext_dq == "1":
print("Do you have one or more new spots or marks like bruises or bleeding under the skin?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2" or ext_dq == "3":
print("Do you have either of the following signs of meningitis?")
print(
"1. My neck is so stiff I can't touch my chin to my chest / I can't stand to look at any light, even a phone or TV screen")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
sharp_pain()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
def mid_east():
print("Have you been to the Middle East in the last 2 weeks?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1" or ext_dq == "2" or ext_dq == "3":
sharp_pain()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
def sharp_pain():
print("Do you get a sharp, stabbing pain in your chest or upper back when you cough or breathe deeply?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
print("Have you coughed up any blood since the problem began?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
print("Have you ever had a blood clot that was treated with blood thinning medicine?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
AE()
elif ext_dq == "2":
print(
"Has a doctor diagnosed you with a condition where there's an increased risk of a blood clot?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
AE()
elif ext_dq == "2":
print("Have you ever had a collapsed lung?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
AE()
elif ext_dq == "2":
print("Have you done either of the following in the last 2 weeks?")
print(
"1. I've been in bed, a chair or wheelchair for 3 days or more / I've been sat down on a journey of 4 hours or more")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
AE()
elif ext_dq == "2":
print("Have you had an operation or broken any bones in the last 12 weeks?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
AE()
elif ext_dq == "2":
print("Do any of these apply?")
print(
"1. I've had cancer treatment / I often take steroid tablets or injections for more than 5 days")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
AE()
elif ext_dq == "2":
GP()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
GP()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
def heart_prob():
print("Has a doctor told you that you have a heart problem?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
print("Has a doctor ever diagnosed you with a heart attack?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
print("Are these symptoms the same as your previous heart attack?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
print("Have you become breathless, or are you more breathless than usual?")
print("1. Yes")
print("2. No / Not sure")
ext_dq = input("")
if ext_dq == "1":
print("Have you got rapid swelling of your lips, face, tongue, mouth or throat?")
print("1. Yes")
print("2. No / Not sure")
ext_dq = input("")
if ext_dq == "1":
print("Are you so ill that you've stopped doing all of your usual daily activities?")
print("1. Yes - I've stopped doing everything I usually do")
print("2. I feel ill but can do some of my usual activities")
print("3. No - I feel well enough to do most of my usual daily activities")
ext_dq = input("")
if ext_dq == "1" or ext_dq == "2." or ext_dq == "3":
print("Have you ever had an allergic reaction which needed emergency hospital care?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2":
print("Did your symptoms start or get much worse within the last hour?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2":
AE()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
print("Do you have any pain in your chest or upper back right now?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
heart_prob()
elif ext_dq == "2":
print("Have you had any pain in your chest or upper back in the last 24 hours?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
heart_prob()
elif ext_dq == "2":
print("Are you so ill that you've stopped doing all of your usual daily activities?")
print("1. Yes - I've stopped doing everything I usually do")
print("2. I feel ill but can do some of my usual activities")
print("3. No - I feel well enough to do most of my usual daily activities")
ext_dq = input("")
if ext_dq == "1":
print("Do you have one or more new spots or marks like bruises or bleeding under the skin?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_2()
elif ext_dq == "2":
print("Do you have either of the following signs of meningitis?")
print(
"1. My neck is so stiff I can't touch my chin to my chest / I can't stand to look at any light, even a phone or TV screen")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_2()
elif ext_dq == "2":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2" or ext_dq == "3":
P999_3()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2":
print("Do you have either of the following?")
print("1. A new continuous cough or a cough that's got worse")
print("2. A new loss of smell of taste")
print("3. No / Not Sure")
ext_dq = input("")
if ext_dq == "1" or ext_dq == "2":
breath_hard()
elif ext_dq == "3":
print("Have you got a high temperature now or had one in the last 2 weeks?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
breath_hard()
elif ext_dq == "2":
print("Are you so ill that you've stopped doing all of your usual daily activities?")
print("1. Yes - I've stopped doing everything I usually do")
print("2. I feel ill but can do some of my usual activities")
print("3. No - I feel well enough to do most of my usual daily activities")
ext_dq = input("")
if ext_dq == "1":
print("Do you have one or more new spots or marks like bruises or bleeding under the skin?")
print("1. Yes")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2":
print("Do you have either of the following signs of meningitis?")
print(
"1. My neck is so stiff I can't touch my chin to my chest / I can't stand to look at any light, even a phone or TV screen")
print("2. No / Not Sure")
ext_dq = input("")
if ext_dq == "1":
P999_1()
elif ext_dq == "2":
mid_east()
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
elif ext_dq == "2" or ext_dq == "3":
mid_east
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
else:
print(
"I'm sorry, but I don't understand what you're trying to say. Please answer with one of the options given.")
# Loop to input while conditions above aren't met
# If a symptom word is detected, it triggers the symptoms function which asks if the user needs a more extensive diagnosis
def symptoms():
# print("It looks like you have:")
print("Would you like to make a more extensive diagnosis?")
symp_choice = input("")
if symp_choice == "yes":
diagnosis()
else:
pass
def main():
# Creats a list of of lists containing values of different postal districts. Postcode Town/Area Region Population Households Nearby districts
locations = locationsGenerator()
# Definse the tags and their markers. Add the tags and markers here
tags = {}
# tags['tags'] = ['marker1','marker2']
tags['greeting'] = ['hi', 'hello', 'greeting', 'hey']
tags['infection'] = ['infection', 'infection rate', 'infectionrate']
tags['death'] = ['death', 'kill']
tags['diagnosis'] = ['diagnosis', 'symptom']
tags['symptoms'] = ['cough', 'temperature', 'fever', 'smell', 'taste', 'cold', 'flu', 'breath', 'tired', 'headache']
tags['ice cream'] = ['ice cream', 'icecream']
tags['question'] = ['?']
tags['yesterday'] = ['yesterday']
tags['yes'] = ['yes', 'sure', 'I do', 'of course']
tags['no'] = ['no', 'I dont', 'nah']
tags['yesterday'] = ['yesterday']
tags['help'] = ['help']
tags['customDate'] = ['custom date']
tags['moreinfo'] = ['heads up', 'more information', 'more info', 'moreinfo']
tags['covid19'] = ['COVID-19', 'coronavirus', 'covid']
tags['favorite'] = ['favourite', 'favorite']
tags['you'] = ['ur', 'your', 'you']
tags['name'] = ['name']
tags['covid20'] = ['covid20', 'COVID-20', 'covid 20', 'covid10', 'covid 10', 'COVID-10', 'covid7', 'covid 7',
'COVID-7', 'covid8', 'covid 8', 'COVID-8', 'covid4', 'covid 4', 'COVID-4', 'covid21',
'covid covi21', 'COVID-21', ]
tags['Simon'] = ['Simon']
tags['how'] = ['how']
tags['are'] = ['are']
tags['sport'] = ['sport']
tags['programming'] = ['programming']
tags['language'] = ['language']
tags['creation'] = ['creation', 'created']
tags['custom'] = ['custom']
tags['date'] = ['date']
# Creates the phrases list based off of the tags. The phrases list will containt markers longer than one word
phrases = phrasesGenerator(tags)
welcome_message()
# This is a counter, it makes it so the report sequence works correctly
counter = 0
developerMode = False
# Repeatedly checks for a question from the user.
while True:
question = input("")
if "/help" in question:
botHelp()
counter = 0
continue # New Matt bit
if "/developer" in question: # New Matt bit
developerMode = True # New Matt bit
counter = 0 # New Matt bit
continue # New Matt bit
# Trys to understand the question by returning tags based off of the question string
meaning = understand(question, tags, phrases, locations)
# Ifs and Elseifs. Checks which tags are in the meaning list, and executes code based off of that
# if "tag" in meaning:
if "greeting" in meaning:
randomHello()
counter = 0
elif "customDate" in meaning:
ratesCustom(tags, phrases, locations)
counter = 0
elif "location provided" in meaning and ("infection" in meaning or "death" in meaning):
ratesToday(meaning, tags, phrases, locations)
counter = 0
elif "moreinfo" in meaning or ('covid19' and 'heads up' in meaning):
wikicontent()
counter = 0
elif "symptoms" in meaning:
symptoms()
counter = 0
elif "diagnosis" in meaning:
diagnosis()
counter = 0 # Matt putting in counter
elif "infection" in meaning:
print("I cannot give you the infection rate if you do not give me a valid location")
counter = 0
elif "death" in meaning:
print("I cannot give you the death rate if you do not dive me a valid location")
counter = 0
elif "ice cream" in meaning and "favorite" in meaning:
print("My favourite ice cream flavour is vanilla!")
counter = 0
elif "you" in meaning and "name" in meaning:
print("My name is Covid-Bot")
counter = 0
elif "Simon" in meaning:
print("I know a Simon! Coventry University is it? Smart chap.")
counter = 0
elif "how" in meaning and "are" in meaning and "you" in meaning:
print("I am happy to be here! Thanks for asking!")
counter = 0
elif "covid20" in meaning:
print("COVID-19 is enough for one planet!")
counter = 0
elif "sport" in meaning and "favorite" in meaning:
print("Chatbots cannot play Sports!")
counter = 0
elif "programming" in meaning and "language" in meaning and "you" in meaning:
print("I was written and developed in Python")
counter = 0
elif "you" in meaning and "creation" in meaning:
print("I was created to give you up to date rates and information related to COVID-19")
counter = 0
# If the user fails to input a question ,The bot will ask the user to input the question once again
if len(meaning) <= 0:
counter = counter + 1
if counter == 1:
print("I don't quite understand what you mean, could you try again?")
# If the user fails to input a question the seccond time (If no tags are recognised), it will ask the user to create a report.
if counter > 1:
print("I wasn't able to understand your question!")
time.sleep(1.0)
print("Would you like to create a report?")
while True:
ReportAns = input("Enter yes or no: ")
if ReportAns == '' or not ReportAns[0].lower() in ['y', 'n']:
print('Please answer with yes or no!')
else:
break
# Source : https://www.youtube.com/watch?v=9Lu6597k2mg&ab_channel=MattParkerTutorialServices explains how to write to files with python
# If the user says yes , will continue to ask for the report and write it to the database
if ReportAns[0].lower() == 'y':
file = open("Reports.txt", "a")
Report = str(input("Write your report here: "))
file.write("\n" + Report + "\n")
file.close()
counter = 0
if ReportAns[0].lower() == 'n':
counter = 0
# cancels
# Gives a 1 in 4 chance to give a random tip
if counter == 0:
options = ["tip", "no tip", "no tip", "no tip"]
randomTip = random.choice(options)
if randomTip == "tip":
tip()
if developerMode == True:
print(meaning)
main()