try to use firestore to save contact list
This commit is contained in:
+10
-5
@@ -34,13 +34,13 @@ def run(playwright, url) -> ResultEnum:
|
|||||||
print(content)
|
print(content)
|
||||||
browser.close()
|
browser.close()
|
||||||
if SORRY_SENTENCE in content:
|
if SORRY_SENTENCE in content:
|
||||||
print("REFUSED")
|
print("result is REFUSED")
|
||||||
return ResultEnum.REFUSED
|
return ResultEnum.REFUSED
|
||||||
elif PENDING_SENTENCE in content:
|
elif PENDING_SENTENCE in content:
|
||||||
print("PENDING")
|
print("result is PENDING")
|
||||||
return ResultEnum.PENDING
|
return ResultEnum.PENDING
|
||||||
else:
|
else:
|
||||||
print("ACCEPTED")
|
print("result is ACCEPTED")
|
||||||
return ResultEnum.ACCEPTED
|
return ResultEnum.ACCEPTED
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +49,12 @@ if __name__ == '__main__':
|
|||||||
# get the list
|
# get the list
|
||||||
db_manager = params.firebase_store_manager
|
db_manager = params.firebase_store_manager
|
||||||
collection = db_manager.get_all_successful_items()
|
collection = db_manager.get_all_successful_items()
|
||||||
|
count = 0
|
||||||
for appointment in collection.stream():
|
for appointment in collection.stream():
|
||||||
|
count = count + 1
|
||||||
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||||
result = check_result_page(reserve_pojo.url)
|
print("status is " + reserve_pojo.accepted)
|
||||||
collection.document(reserve_pojo.id).update({u'accepted': result.name})
|
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)
|
||||||
|
|||||||
Binary file not shown.
+31
-1
@@ -7,8 +7,10 @@ import params
|
|||||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||||
from pojo.SimInfoPojo import SimInfoPojo
|
from pojo.SimInfoPojo import SimInfoPojo
|
||||||
from pojo.contact_pojo import ContactPojo
|
from pojo.contact_pojo import ContactPojo
|
||||||
|
from utils.excel_reader import ExcelHelper
|
||||||
|
|
||||||
ERROR_COLLECTION_NAME = "error_items"
|
ERROR_COLLECTION_NAME = "error_items"
|
||||||
|
CONTACT_COLLECTION_NAME = "contact_list"
|
||||||
SIM_INFOS = "sim_infos"
|
SIM_INFOS = "sim_infos"
|
||||||
TIMEOUT = "timeout_items"
|
TIMEOUT = "timeout_items"
|
||||||
|
|
||||||
@@ -20,6 +22,11 @@ class DataManager:
|
|||||||
cred = credentials.Certificate("appointment.json")
|
cred = credentials.Certificate("appointment.json")
|
||||||
self._app = firebase_admin.initialize_app(cred)
|
self._app = firebase_admin.initialize_app(cred)
|
||||||
self._db = firestore.client()
|
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):
|
def get_all_error_items(self):
|
||||||
pass
|
pass
|
||||||
@@ -35,6 +42,16 @@ class DataManager:
|
|||||||
def save_sim_info(self, simInfoPojo: SimInfoPojo):
|
def save_sim_info(self, simInfoPojo: SimInfoPojo):
|
||||||
doc_ref = self._db.collection(SIM_INFOS).document(simInfoPojo.phone)
|
doc_ref = self._db.collection(SIM_INFOS).document(simInfoPojo.phone)
|
||||||
doc_ref.set(simInfoPojo.to_firestore_dict())
|
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):
|
def save(self, result: ReserveResultPojo):
|
||||||
if result.type == PublishType.SUCCESS:
|
if result.type == PublishType.SUCCESS:
|
||||||
@@ -89,7 +106,20 @@ class DataManager:
|
|||||||
row += 1
|
row += 1
|
||||||
workbook.close()
|
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__':
|
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()
|
# params.firebase_store_manager.clear_all_sim_info()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class ReserveResultPojo:
|
|||||||
lastName: None
|
lastName: None
|
||||||
email: None
|
email: None
|
||||||
id = None
|
id = None
|
||||||
|
accepted = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_firestore_dict(source):
|
def from_firestore_dict(source):
|
||||||
@@ -30,9 +31,11 @@ class ReserveResultPojo:
|
|||||||
email = source['email']
|
email = source['email']
|
||||||
lastName = source['lastName']
|
lastName = source['lastName']
|
||||||
firstName = source['firstName']
|
firstName = source['firstName']
|
||||||
|
accepted = source['accepted']
|
||||||
result = ReserveResultPojo(type=publish_type, phone=phone,
|
result = ReserveResultPojo(type=publish_type, phone=phone,
|
||||||
message=message, url=url, email=email,
|
message=message, url=url, email=email,
|
||||||
firstName=firstName, lastName=lastName)
|
firstName=firstName, lastName=lastName)
|
||||||
|
result.accepted = accepted
|
||||||
result.id = id
|
result.id = id
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
+19
-2
@@ -9,14 +9,17 @@ class ContactPojo:
|
|||||||
first_name: str
|
first_name: str
|
||||||
mail: str
|
mail: str
|
||||||
ccid: 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.phone = phone_number
|
||||||
self.passport = passport_number
|
self.passport = passport_number
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
self.ccid = ccid
|
self.ccid = ccid
|
||||||
self.mail = mail
|
self.mail = mail
|
||||||
|
self.position = position
|
||||||
|
|
||||||
def to_firestore_dict(self):
|
def to_firestore_dict(self):
|
||||||
dest = {
|
dest = {
|
||||||
@@ -25,7 +28,21 @@ class ContactPojo:
|
|||||||
u'last_name': self.last_name,
|
u'last_name': self.last_name,
|
||||||
u'first_name': self.first_name,
|
u'first_name': self.first_name,
|
||||||
u'mail': self.mail,
|
u'mail': self.mail,
|
||||||
u'ccid': self.ccid
|
u'ccid': self.ccid,
|
||||||
|
u'position': self.position
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest
|
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
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class ExcelHelper:
|
|||||||
first_name=first_name,
|
first_name=first_name,
|
||||||
ccid=contact_dict['ccid'],
|
ccid=contact_dict['ccid'],
|
||||||
passport_number=contact_dict['passport'],
|
passport_number=contact_dict['passport'],
|
||||||
|
position=contact_dict['position'],
|
||||||
mail=contact_dict['email'])
|
mail=contact_dict['email'])
|
||||||
contact_list.append(contact)
|
contact_list.append(contact)
|
||||||
return contact_list
|
return contact_list
|
||||||
|
|||||||
Reference in New Issue
Block a user