handle duplicated
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class PublishType(Enum):
|
||||
SUCCESS = "SUCCESS"
|
||||
ERROR = "ERROR"
|
||||
PENDING = "PENDING"
|
||||
DUPLICATED = "DUPLICATED"
|
||||
|
||||
|
||||
@dataclass_json
|
||||
|
||||
@@ -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 aujourd’hui."
|
||||
|
||||
|
||||
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:
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user