diff --git a/check_results.py b/check_results.py index 0ddf309..4766d1f 100644 --- a/check_results.py +++ b/check_results.py @@ -34,13 +34,13 @@ def run(playwright, url) -> ResultEnum: print(content) browser.close() if SORRY_SENTENCE in content: - print("REFUSED") + print("result is REFUSED") return ResultEnum.REFUSED elif PENDING_SENTENCE in content: - print("PENDING") + print("result is PENDING") return ResultEnum.PENDING else: - print("ACCEPTED") + print("result is ACCEPTED") return ResultEnum.ACCEPTED @@ -49,7 +49,12 @@ if __name__ == '__main__': # get the list db_manager = params.firebase_store_manager collection = db_manager.get_all_successful_items() + count = 0 for appointment in collection.stream(): + count = count + 1 reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict()) - result = check_result_page(reserve_pojo.url) - collection.document(reserve_pojo.id).update({u'accepted': result.name}) + print("status is " + reserve_pojo.accepted) + if reserve_pojo.accepted is None or ResultEnum.PENDING.value == reserve_pojo.accepted: + result = check_result_page(reserve_pojo.url) + collection.document(reserve_pojo.id).update({u'accepted': result.name}) + print(count) diff --git a/contact.xlsx b/contact.xlsx index 6841c28..c6c2489 100644 Binary files a/contact.xlsx and b/contact.xlsx differ diff --git a/db/DbManager.py b/db/DbManager.py index a44c58c..7c6d16c 100644 --- a/db/DbManager.py +++ b/db/DbManager.py @@ -7,8 +7,10 @@ import params from pojo.ReserveResultPojo import ReserveResultPojo, PublishType from pojo.SimInfoPojo import SimInfoPojo from pojo.contact_pojo import ContactPojo +from utils.excel_reader import ExcelHelper ERROR_COLLECTION_NAME = "error_items" +CONTACT_COLLECTION_NAME = "contact_list" SIM_INFOS = "sim_infos" TIMEOUT = "timeout_items" @@ -20,6 +22,11 @@ class DataManager: cred = credentials.Certificate("appointment.json") self._app = firebase_admin.initialize_app(cred) self._db = firestore.client() + contact_collection = self._db.collection(CONTACT_COLLECTION_NAME) + self._contact_list = [] + for contact in contact_collection.stream(): + contact_pojo = ContactPojo.from_firestore_dict(contact.to_dict()) + self._contact_list.append(contact_pojo) def get_all_error_items(self): pass @@ -35,6 +42,16 @@ class DataManager: def save_sim_info(self, simInfoPojo: SimInfoPojo): doc_ref = self._db.collection(SIM_INFOS).document(simInfoPojo.phone) doc_ref.set(simInfoPojo.to_firestore_dict()) + contact_found = [contact for contact in self._contact_list if contact.position == simInfoPojo.position] + if len(contact_found) > 0: + # link the phone number with contact + contact = contact_found[0] + phone = simInfoPojo.phone[2:len(simInfoPojo.phone)] + ccid = simInfoPojo.ccid + self._db.collection(CONTACT_COLLECTION_NAME).document(contact.passport).update( + {'phone': phone, 'ccid': ccid}) + else: + print("error, contact not found") def save(self, result: ReserveResultPojo): if result.type == PublishType.SUCCESS: @@ -89,7 +106,20 @@ class DataManager: row += 1 workbook.close() + def upload_contact_list_to_cloud(self): + excel_reader = ExcelHelper() + contacts = excel_reader.read_contacts() + collections = self._db.collection(CONTACT_COLLECTION_NAME) + for contact in contacts: + new_contact = collections.document(contact.passport) + new_contact.set(contact.to_firestore_dict()) + + def read_contacts_from_db(self) -> list: + contact_collection = self._db.collection(CONTACT_COLLECTION_NAME) + return contact_collection + if __name__ == '__main__': - params.firebase_store_manager.save_to_excel() + params.firebase_store_manager.upload_contact_list_to_cloud() + # params.firebase_store_manager.save_to_excel() # params.firebase_store_manager.clear_all_sim_info() diff --git a/pojo/ReserveResultPojo.py b/pojo/ReserveResultPojo.py index eb71ce4..4994a58 100644 --- a/pojo/ReserveResultPojo.py +++ b/pojo/ReserveResultPojo.py @@ -19,6 +19,7 @@ class ReserveResultPojo: lastName: None email: None id = None + accepted = None @staticmethod def from_firestore_dict(source): @@ -30,9 +31,11 @@ class ReserveResultPojo: email = source['email'] lastName = source['lastName'] firstName = source['firstName'] + accepted = source['accepted'] result = ReserveResultPojo(type=publish_type, phone=phone, message=message, url=url, email=email, firstName=firstName, lastName=lastName) + result.accepted = accepted result.id = id return result diff --git a/pojo/contact_pojo.py b/pojo/contact_pojo.py index b438b18..fccf059 100644 --- a/pojo/contact_pojo.py +++ b/pojo/contact_pojo.py @@ -9,14 +9,17 @@ class ContactPojo: first_name: str mail: str ccid: str + position: int - def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, ccid: str, mail: str): + def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, ccid: str, mail: str, + position: int): self.phone = phone_number self.passport = passport_number self.last_name = last_name self.first_name = first_name self.ccid = ccid self.mail = mail + self.position = position def to_firestore_dict(self): dest = { @@ -25,7 +28,21 @@ class ContactPojo: u'last_name': self.last_name, u'first_name': self.first_name, u'mail': self.mail, - u'ccid': self.ccid + u'ccid': self.ccid, + u'position': self.position } return dest + + @staticmethod + def from_firestore_dict(source): + ccid = source['ccid'] + phone = source['phone'] + position = source['position'] + passport = source['passport'] + email = source['mail'] + lastName = source['last_name'] + firstName = source['last_name'] + result = ContactPojo(ccid=ccid, phone_number=phone, passport_number=passport, position=position, mail=email, + last_name=lastName, first_name=firstName) + return result diff --git a/utils/excel_reader.py b/utils/excel_reader.py index 1a4ce04..9175977 100644 --- a/utils/excel_reader.py +++ b/utils/excel_reader.py @@ -38,6 +38,7 @@ class ExcelHelper: first_name=first_name, ccid=contact_dict['ccid'], passport_number=contact_dict['passport'], + position=contact_dict['position'], mail=contact_dict['email']) contact_list.append(contact) return contact_list