Skip to content
Permalink
Browse files

Fixed small bugs, cleaned code

- Fixed a small bug showing the error messages

- Removed unnecessary code
  • Loading branch information
mateussa committed Nov 24, 2017
1 parent 9bb8bc4 commit 91ca15bbee9f0aa85dd4bfceab359cde2fda5e47
Showing with 21 additions and 41 deletions.
  1. +8 −8 DataAPI.py
  2. +13 −33 Server.py
@@ -235,19 +235,19 @@ def getQuestion(category, difficulty, nrQuestions = 1, qSource = "OpentDB"): # A

if ("Error" in questionSet): # Return every thing as a list to keep the same structure as getting multiple questions
if (questionSet[1] == 0):
return(["Error", "There was an error opening the URL"])
return([("Error", "There was an error opening the URL")])
elif (questionSet[1] == 1):
return(["Error", "Error reading JSON data"])
return([("Error", "Error reading JSON data")])
elif (questionSet[1] == 2):
return(["Error", "The number of questions requested not valid"])
return([("Error", "The number of questions requested not valid")])
elif (questionSet[1] == 3):
return(["Error", "Category not valid"])
return([("Error", "Category not valid")])
elif (questionSet[1] == 4):
return(["Error", "Difficulty not valid"])
return([("Error", "Difficulty not valid")])
elif (questionSet[1] == 5):
return(["Error", "No results were found"])
return([("Error", "No results were found")])
elif (questionSet[1] == 6):
return(["Error", "Invalid parameter"])
return([("Error", "Invalid parameter")])
elif (questionSet[1] == 7):
import os

@@ -256,7 +256,7 @@ def getQuestion(category, difficulty, nrQuestions = 1, qSource = "OpentDB"): # A
os.remove("./data/token.jeff")
questionSet = getOpentDB(category, difficulty, nrQuestions)
if ("Error" in questionSet):
return(["Error", "Token not found or all available question were used"])
return([("Error", "Token not found or all available question were used")])

return(questionSet)

@@ -57,7 +57,7 @@ def askSomething(answerType, sendMessages, noAnswers, defaultAnswer): # Andre
break

if (answer[1] == 2): # If the user asked a question
if (type(answer[0]) == tuple): # Send two messages, the text and the link of the google search
if (type(answer[0]) == tuple): # Send two messages, i.e. the text and the link of the google search
sendMessage(answer[0][0], False)
sendMessage(answer[0][1], False)
else:
@@ -68,7 +68,7 @@ def askSomething(answerType, sendMessages, noAnswers, defaultAnswer): # Andre
elif (answer[1] == 5): # If the user doesn't want to answer
sendMessage("You should, it would be more fun!")
noAnswers.pop(len(noAnswers) - 1)
else:
elif (answer[1] != answerType):
sendMessage("Sorry I didn't undertood that.", False)
sendMessage("Can you repeat please.")
noAnswers.pop(len(noAnswers) - 1)
@@ -94,13 +94,12 @@ def oneQuestion(qType): # Andre
["You can choose a category from the list above, like 'Music'.",
"Hmmm, I see you are afraid of making a mistake."], "Any")
else:
receivedMessage = ""
receivedMessage = "" # Create the variable anyway, because it can be another type of question

# Get a question and answers, from the user choice
questionSet = getQuestion(receivedMessage, "", 1, qType)[0]
if ("Error" in questionSet):
sendMessage(questionSet[1], False)
sendMessage("Lets try again.", False)
sendMessage("{}: {}".format(questionSet[0], questionSet[1]), False)
return(questionSet)

# If question set of Multiple type
@@ -120,24 +119,10 @@ def oneQuestion(qType): # Andre
["You can choose one of the options.",
"Hmmm, I see you are afraid of making a mistake."], "X")

# If question set of Birthday type
elif (questionSet["Type"] == "Birthday"):
receivedMessage = askSomething(0, [questionSet["Question"]],
["You can try a random one if felling lucky.",
"Hmmm, I see you are afraid of making a mistake."], "X")
questionSet[receivedMessage.upper()] = receivedMessage

# If question set of History type
elif (questionSet["Type"] == "History"):
# If question set of Birthday or History or Quote type
elif (questionSet["Type"] in ["Birthday"], "History", "Quote"):
receivedMessage = askSomething(0, [questionSet["Question"]],
["You can try a random one if felling lucky.",
"Hmmm, I see you are afraid of making a mistake."], "X")
questionSet[receivedMessage.upper()] = receivedMessage

# If question set of Quote type
elif (questionSet["Type"] == "Quote"):
receivedMessage = askSomething(0, [questionSet["Question"]],
["You can try a random one if felling lucky.",
["You can try a random answer if felling lucky.",
"Hmmm, I see you are afraid of making a mistake."], "X")
questionSet[receivedMessage.upper()] = receivedMessage

@@ -157,16 +142,12 @@ def quizChallange(nrQuestions): # Andre
with the lenght of the choosen input '''
if (nrQuestions < 1 or nrQuestions > 50):
sendMessage("For a Quiz challenge ou have to choose between 2 and 50 quesitons.")
return(True)
return(nrQuestions)

cat = getCategories(True, 3)
if ("Error" in cat):
sendMessage("{}: {}".format(cat[0], cat[1]), False)
if (cat[1] == 7):
sendMessage("Lets try again.")
return(True)
else:
return(False)
return(cat)

receivedMessage = askSomething(-1, ["Pick a subject.", cat[0], cat[1], cat[2]],
["You can choose a category from the list above, like 'Music'.",
@@ -176,11 +157,10 @@ def quizChallange(nrQuestions): # Andre
# Get a question and answers, from the user choice
qChaSet = getQuestion(receivedMessage, "", nrQuestions)
if ("Error" in qChaSet):
sendMessage(qChaSet[1], False)
sendMessage("Lets try again.", False)
return (True)
sendMessage("{}: {}".format(qChaSet[0], qChaSet[1]), False)
return(qChaSet)

Score = 0
Score = 0 # Initialize the variable to keep track of the right answers

for questionSet in qChaSet:
# If question set of multiple type
@@ -231,7 +211,7 @@ def funFacts(): # Andre




# Start server #
####################
# #
# CONNECTION #

0 comments on commit 91ca15b

Please sign in to comment.
You can’t perform that action at this time.