update siminfo

This commit is contained in:
2022-04-05 19:23:42 +02:00
parent 35afd9bcd7
commit 7bfb5bf1df
3 changed files with 19 additions and 10 deletions
+15 -9
View File
@@ -18,6 +18,8 @@ MAIL_COLLECTION_NAME = "mail_list"
SIM_INFOS = "sim_infos"
TIMEOUT = "timeout_items"
excel_reader = ExcelHelper()
class DataManager:
batch_size = 20
@@ -26,11 +28,7 @@ class DataManager:
cred = credentials.Certificate(definitions.ROOT_DIR + "/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)
self._contact_list = excel_reader.read_contacts()
def get_all_error_items(self):
pass
@@ -49,7 +47,8 @@ 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]
contact_found = [contact for contact in self._contact_list if
contact.ccid.replace("F", "") == simInfoPojo.ccid.replace("F", "")]
if len(contact_found) > 0:
# link the phone number with contact
contact = contact_found[0]
@@ -96,10 +95,15 @@ class DataManager:
def save_to_excel(self):
# Start from the first cell. Rows and columns are zero indexed.
sim_info_list = []
for sim in self.get_all_sim_infos().stream():
print(sim)
sim_pojo = SimInfoPojo.from_firestore_dict(sim.to_dict())
contact_list_found = [contact for contact in self._contact_list if
contact.ccid.replace("F", "") == sim_pojo.ccid.replace("F", "")]
if len(contact_list_found) > 0:
sim_pojo.email = contact_list_found[0].mail
sim_pojo.name = contact_list_found[0].first_name + " " + contact_list_found[0].last_name
sim_pojo.passport = contact_list_found[0].passport
sim_info_list.append(sim_pojo)
row = 0
col = 0
@@ -113,8 +117,10 @@ class DataManager:
else:
worksheet.write(row, col, info.phone)
worksheet.write(row, col + 1, info.ccid)
worksheet.write(row, col + 2, info.operator)
worksheet.write(row, col + 3, info.position)
worksheet.write(row, col + 2, info.name)
worksheet.write(row, col + 3, info.passport)
worksheet.write(row, col + 4, info.email)
worksheet.write(row, col + 5, info.position)
row += 1
workbook.close()
+3
View File
@@ -9,6 +9,9 @@ class SimInfoPojo:
operator: str
slot_position: str
sim_position: str
name: str
passport: str
email: str
def __init__(self, phone: str, ccid: str, position, operator: str, slot_position, sim_position,
update_at: int = int(time.time())):
+1 -1
View File
@@ -37,7 +37,7 @@ class ExcelHelper:
return user_agents
def read_contacts(self) -> list:
contact_list_in_json = pandas.read_excel(r'./contact.xlsx').to_json(orient='records')
contact_list_in_json = pandas.read_excel(definitions.ROOT_DIR + "/contact.xlsx").to_json(orient='records')
contact_dict_list = json.loads(contact_list_in_json)
contact_list = []
for contact_dict in contact_dict_list: