From ce00b923ffb679c68683bdf012059354dbb9b39b Mon Sep 17 00:00:00 2001 From: westernmeadow Date: Mon, 18 Sep 2023 16:46:01 -0700 Subject: [PATCH] added delay after closing file in read_file() --- Forums/Initialization/prepare_parser.py | 6 ++++-- MarketPlaces/Initialization/prepare_parser.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Forums/Initialization/prepare_parser.py b/Forums/Initialization/prepare_parser.py index ac1523f..3d2f388 100644 --- a/Forums/Initialization/prepare_parser.py +++ b/Forums/Initialization/prepare_parser.py @@ -97,6 +97,7 @@ def read_file(filePath, createLog, logFile): html = codecs.open(filePath.strip('\n'), encoding='utf8') soup = BeautifulSoup(html, "html.parser") html.close() + time.sleep(0.01) # making sure the file is closed before returning soup object return soup except: @@ -104,6 +105,7 @@ def read_file(filePath, createLog, logFile): html = open(filePath.strip('\n')) soup = BeautifulSoup(html, "html.parser") html.close() + time.sleep(0.01) # making sure the file is closed before returning soup object return soup except: @@ -212,7 +214,7 @@ def persist_record(url, rec, cur, con, createLog, logFile, listingFile, descript def move_file(filePath, createLog, logFile): source = filePath - destination = filePath.replace(os.path.basename(filePath), "") + r'Read/' + os.path.basename(filePath) + destination = filePath.replace(os.path.basename(filePath), "") + 'Read\\' + os.path.basename(filePath) try: shutil.move(source, destination, shutil.copy2) @@ -250,7 +252,7 @@ def new_parse(forum, url, createLog): # Creating the tables (The database should be created manually) create_database(cur, con) - mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums/" + forum + "/HTML_Pages") + mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums\\" + forum + "\\HTML_Pages") # Creating the log file for each Forum if createLog: diff --git a/MarketPlaces/Initialization/prepare_parser.py b/MarketPlaces/Initialization/prepare_parser.py index b94723f..9cfe2a9 100644 --- a/MarketPlaces/Initialization/prepare_parser.py +++ b/MarketPlaces/Initialization/prepare_parser.py @@ -107,6 +107,7 @@ def read_file(filePath, createLog, logFile): html = codecs.open(filePath.strip('\n'), encoding='utf8') soup = BeautifulSoup(html, "html.parser") html.close() + time.sleep(0.01) # making sure the file is closed before returning soup object return soup except: @@ -114,6 +115,7 @@ def read_file(filePath, createLog, logFile): html = open(filePath.strip('\n')) soup = BeautifulSoup(html, "html.parser") html.close() + time.sleep(0.01) # making sure the file is closed before returning soup object return soup except: @@ -271,7 +273,7 @@ def persist_record(url, rec, cur, con, createLog, logFile, listingFile, descript def move_file(filePath, createLog, logFile): source = filePath - destination = filePath.replace(os.path.basename(filePath), "") + r'Read/' + os.path.basename(filePath) + destination = filePath.replace(os.path.basename(filePath), "") + 'Read\\' + os.path.basename(filePath) try: shutil.move(source, destination, shutil.copy2) @@ -307,7 +309,7 @@ def new_parse(marketPlace, url, createLog): # Creating the tables (The database should be created manually) create_database(cur, con) - mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces/" + marketPlace + "/HTML_Pages") + mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces\\" + marketPlace + "\\HTML_Pages") # Creating the log file for each Forum if createLog: