handle duplicated

This commit is contained in:
2022-08-12 13:01:16 +02:00
parent 20e43b9c30
commit 241cdda0f9
4 changed files with 14 additions and 7 deletions
+2 -2
View File
@@ -181,11 +181,11 @@ class MongoDbManager:
except Exception as error:
self.logger.info(error)
def link_validated_for_result(self, link: str):
def link_validated_for_result(self, link: str, state="True"):
id = link.split("/")[-1]
collection_name = str(datetime.date.today())
collection = self.db[collection_name]
collection.find_one_and_update({'_id': id}, {"$set": {"url_validated": "True"}}, upsert=False)
collection.find_one_and_update({'_id': id}, {"$set": {"url_validated": state}}, upsert=False)
MONGO_STORE_MANAGER = MongoDbManager()
+1 -1
View File
@@ -163,7 +163,7 @@ def read_mails():
if need_to_valid_url(url, successful_items):
url_validator = LinkValidator(url)
print("need to validate url: " + url)
executor.submit(url_validator.start_page, params.get_proxy(ProxyType.BRIGHT_DATA), True)
executor.submit(url_validator.start_page, params.get_proxy(ProxyType.BRIGHT_DATA), False)
else:
print("do not need to click url --> {}".format(mail))
+1
View File
@@ -11,6 +11,7 @@ class PublishType(Enum):
SUCCESS = "SUCCESS"
ERROR = "ERROR"
PENDING = "PENDING"
DUPLICATED = "DUPLICATED"
@dataclass_json
+10 -4
View File
@@ -17,6 +17,7 @@ TIME_OUT = 10 * 60 * 1000 # 10 mins
PAGE_TIMEOUT = 40000
CONFIRMED_MESSAGE_FR = "Votre demande de rendez-vous Maroquinerie a bien été enregistrée et nous vous en remercions."
SORRY_SENTENCE_FR = "nous sommes sincèrement désolés de n'avoir pu vous satisfaire cette fois-ci"
DOUBLE_REQUEST_ERROR_MESSAGE_FR = "Une demande avec les données saisies a déjà été validée aujourdhui."
class LinkValidator:
@@ -100,6 +101,9 @@ class LinkValidator:
elif SORRY_SENTENCE_FR in message:
# publish the successful message
self.publish_message_to_queue(PublishType.SUCCESS)
elif DOUBLE_REQUEST_ERROR_MESSAGE_FR in message:
# publish the successful message
self.publish_message_to_queue(PublishType.DUPLICATED)
except Exception as error:
self.logger.error(error)
@@ -116,8 +120,10 @@ class LinkValidator:
def publish_message_to_queue(self, status: PublishType):
# create the message
MONGO_STORE_MANAGER.link_validated_for_result(self.page.url)
if status is PublishType.SUCCESS:
self.on_success()
time.sleep(2)
self.browser.close()
MONGO_STORE_MANAGER.link_validated_for_result(self.page.url)
else:
MONGO_STORE_MANAGER.link_validated_for_result(self.page.url, state=status.name)
self.on_success()
time.sleep(2)
self.browser.close()