added check accepted or not before sending request

This commit is contained in:
2022-07-25 10:53:29 +02:00
parent 418699635e
commit 3160fefdab
3 changed files with 68 additions and 3 deletions
+11
View File
@@ -41,6 +41,17 @@ class MongoDbManager:
except Exception as Error: except Exception as Error:
self.logger.info(Error) self.logger.info(Error)
def get_all_accepted_appointments(self) -> list:
collection_name = ACCEPTED_APPOINTMENT_LIST
appointment_list_contacts = []
try:
collection_to_use = self.db[collection_name]
for document in collection_to_use.find():
appointment_list_contacts.append(AcceptedAppointmentPojo.from_firestore_dict(document))
except Exception as error:
self.logger.info(error)
return appointment_list_contacts
def insert_captcha_error_contact(self, contact: ContactPojo): def insert_captcha_error_contact(self, contact: ContactPojo):
day = str(datetime.date.today()) day = str(datetime.date.today())
collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day collection_name = CAPTCHA_ERROR_COLLECTION_PREFIX + day
+38 -2
View File
@@ -1,6 +1,6 @@
import time import time
from src.pojo.ReserveResultPojo import ReserveResultPojo from src.pojo.ReserveResultPojo import ReserveResultPojo, PublishType
class AcceptedAppointmentPojo(ReserveResultPojo): class AcceptedAppointmentPojo(ReserveResultPojo):
@@ -46,7 +46,43 @@ class AcceptedAppointmentPojo(ReserveResultPojo):
@staticmethod @staticmethod
def from_firestore_dict(source): def from_firestore_dict(source):
result = ReserveResultPojo.from_firestore_dict(source) if 'type' in source:
publish_type = source['type']
if publish_type:
publish_type = PublishType[publish_type]
else:
publish_type = PublishType.SUCCESS
phone = source['phone']
url = source['url']
id = source['id']
email = source['email']
lastName = source['lastName']
firstName = source['firstName']
result = ReserveResultPojo(type=publish_type, phone=phone,
message="", url=url, email=email,
firstName=firstName, lastName=lastName)
if 'accepted' in source:
accepted = source['accepted']
result.accepted = accepted
if 'source' in source:
source_from = source['source']
result.source_from = source_from
if 'sim_position' in source:
sim_position = source['sim_position']
result.sim_position = sim_position
if 'slot_position' in source:
slot_position = source['slot_position']
result.slot_position = slot_position
if 'passport' in source:
passport = source['passport']
result.passport = passport
if 'ccid' in source:
ccid = source['ccid']
result.ccid = ccid
if 'store_type' in source:
store_type = source['store_type']
result.store_type = store_type
result.id = id
accepted_pojo = AcceptedAppointmentPojo.from_reserve(result) accepted_pojo = AcceptedAppointmentPojo.from_reserve(result)
if 'accepted_at' in source: if 'accepted_at' in source:
accepted_at = source['accepted_at'] accepted_at = source['accepted_at']
+19 -1
View File
@@ -4,6 +4,7 @@ from src.db.mongo_manager import MONGO_STORE_MANAGER
from src.pojo.contact_pojo import ContactPojo from src.pojo.contact_pojo import ContactPojo
SEVEN_DAYS_IN_S = 7 * 24 * 3600 SEVEN_DAYS_IN_S = 7 * 24 * 3600
TWO_WEEKS_IN_S = 2 * SEVEN_DAYS_IN_S
def is_already_sent(contact: ContactPojo) -> bool: def is_already_sent(contact: ContactPojo) -> bool:
@@ -24,5 +25,22 @@ def is_in_white_list(contact: ContactPojo) -> bool:
return True return True
def is_in_accepted_list(contact: ContactPojo) -> bool:
accepted_appointment_list = MONGO_STORE_MANAGER.get_all_accepted_appointments()
for accepted_contact in accepted_appointment_list:
if contact.mail == accepted_contact.email:
# check date
return accepted_contact.accepted_at + TWO_WEEKS_IN_S > time.time()
return False
def can_send_request(contact: ContactPojo) -> bool: def can_send_request(contact: ContactPojo) -> bool:
return is_in_white_list(contact) and (not is_already_sent(contact=contact)) return is_in_white_list(contact) and (not is_already_sent(contact=contact)) and (
not is_in_accepted_list(contact=contact))
if __name__ == '__main__':
contact = ContactPojo(phone_number='605764105', passport_number='23023672', last_name='Jia', first_name='Roujin',
mail='alanobierx@hotmail.com')
print(can_send_request(contact))