From 181859f0075827d181ad4a4d6f02ab9ccf435ba4 Mon Sep 17 00:00:00 2001 From: David Lawler Date: Tue, 1 Mar 2022 09:18:27 +1000 Subject: [PATCH] question logging working --- asked_questions_log.txt | 4 ++++ main.py | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 asked_questions_log.txt diff --git a/asked_questions_log.txt b/asked_questions_log.txt new file mode 100644 index 0000000..d033c45 --- /dev/null +++ b/asked_questions_log.txt @@ -0,0 +1,4 @@ +hi /nboo /n + +test +test2 \ No newline at end of file diff --git a/main.py b/main.py index e7e5eb4..1539a87 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,22 @@ import json -#print("Hello, I am a question answering bot.\n") -#Question = str(input("Please enter a question, and press the ENTER key:\n")) -#print ("I think that you asked " + (Question)) +print("Hello, I am a question answering bot.\n") +question = str(input("Please enter a question, and press the ENTER key:\n")) +print ("I think that you asked " + (question)) + +#Record question to asked question log file +#with open('asked_questions_log.txt', 'a') as f: +# f.write('{} {}'.format(question,"/n")) + +# Open the file in append & read mode ('a+') +with open("asked_questions_log.txt", "a+") as file_object: + # Move read cursor to the start of file. + file_object.seek(0) + # If file is not empty then append '\n' + data = file_object.read(100) + if len(data) > 0 : + file_object.write("\n") + # Append text at the end of file + file_object.write(question) #def jaccard_similarity(list1, list2): # s1 = set(list1)