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):
3434 self .scraped_data = data .read ()
3535 self .scraped_data = json .loads (self .scraped_data )
3636 except :
37- open (os .getcwd ()+ "/hash_table.json " , 'w' )
37+ open (os .getcwd ()+ "/hash_table.json" , 'w' )
3838
3939 self .update = False
4040
41- def update_hashes (self ):
41+ def append_changes (self ):
4242
43- # Writes the updated self.hashes list to the dat file
4443 with open (os .getcwd ()+ "/hash_table.json" , 'w' ) as data :
4544 json_string = json .dumps (self .scraped_data , ensure_ascii = False )
4645 data .write (json_string )
@@ -111,21 +110,24 @@ def answer_question(self, browser):
111110 try :
112111 answers = self .scraped_data [f'{ self .question_hash } ' ]
113112
113+ # answer the question
114114 for k in answers :
115115 for m in self .answers_in_page :
116116 if k == m :
117117 self .click_correct_button (browser ,k )
118118 answered = True
119119 time .sleep (0.4 )
120120
121+ # if the question is in the json file but has multiple answers that are not stored in the table
121122 if answered == False :
122123
123124 self .scraped_data [f'{ self .question_hash } ' ][1 ].append (self .get_correct_answer (browser ))
124- self .update_hashes ()
125+ self .append_changes ()
125126
126- except :
127+ # if the question is not in the json file
128+ except :
127129
128130 self .scraped_data [f'{ self .question_hash } ' ] = [self .get_correct_answer (browser )]
129- self .update_hashes ()
131+ self .append_changes ()
130132
131133
You can’t perform that action at this time.
0 commit comments