File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -34,13 +34,12 @@ def read_file(self):
34
34
self .scraped_data = data .read ()
35
35
self .scraped_data = json .loads (self .scraped_data )
36
36
except :
37
- open (os .getcwd ()+ "/hash_table.json " , 'w' )
37
+ open (os .getcwd ()+ "/hash_table.json" , 'w' )
38
38
39
39
self .update = False
40
40
41
- def update_hashes (self ):
41
+ def append_changes (self ):
42
42
43
- # Writes the updated self.hashes list to the dat file
44
43
with open (os .getcwd ()+ "/hash_table.json" , 'w' ) as data :
45
44
json_string = json .dumps (self .scraped_data , ensure_ascii = False )
46
45
data .write (json_string )
@@ -111,21 +110,24 @@ def answer_question(self, browser):
111
110
try :
112
111
answers = self .scraped_data [f'{ self .question_hash } ' ]
113
112
113
+ # answer the question
114
114
for k in answers :
115
115
for m in self .answers_in_page :
116
116
if k == m :
117
117
self .click_correct_button (browser ,k )
118
118
answered = True
119
119
time .sleep (0.4 )
120
120
121
+ # if the question is in the json file but has multiple answers that are not stored in the table
121
122
if answered == False :
122
123
123
124
self .scraped_data [f'{ self .question_hash } ' ][1 ].append (self .get_correct_answer (browser ))
124
- self .update_hashes ()
125
+ self .append_changes ()
125
126
126
- except :
127
+ # if the question is not in the json file
128
+ except :
127
129
128
130
self .scraped_data [f'{ self .question_hash } ' ] = [self .get_correct_answer (browser )]
129
- self .update_hashes ()
131
+ self .append_changes ()
130
132
131
133
You can’t perform that action at this time.
0 commit comments