import datetime import firebase_admin import xlsxwriter as xlsxwriter from firebase_admin import credentials, firestore import params from pojo.ReserveResultPojo import ReserveResultPojo, PublishType from pojo.SimInfoPojo import SimInfoPojo from pojo.contact_pojo import ContactPojo ERROR_COLLECTION_NAME = "error_items" SIM_INFOS = "sim_infos" TIMEOUT = "timeout_items" class DataManager: def __init__(self): cred = credentials.Certificate("appointment.json") self._app = firebase_admin.initialize_app(cred) self._db = firestore.client() def get_all_error_items(self): pass def get_all_sim_infos(self): sim_info_collection = self._db.collection(SIM_INFOS) return sim_info_collection def get_all_successful_items(self): doc_ref = self._db.collection(str(datetime.date.today())) return doc_ref def save_sim_info(self, simInfoPojo: SimInfoPojo): doc_ref = self._db.collection(SIM_INFOS).document(simInfoPojo.phone) doc_ref.set(simInfoPojo.to_firestore_dict()) def save(self, result: ReserveResultPojo): if result.type == PublishType.SUCCESS: # get id id = result.url.split("/")[-1] result.id = id document_name = str(datetime.date.today()) doc_ref = self._db.collection(document_name).document(result.id) doc_ref.set(result.to_firestore_dict()) else: doc_ref = self._db.collection(ERROR_COLLECTION_NAME).document(result.phone) doc_ref.set(result.to_firestore_dict()) def save_timeout_contact(self, contact: ContactPojo): doc_ref = self._db.collection(TIMEOUT).document(str(contact.phone)) doc_ref.set(contact.to_firestore_dict()) if __name__ == '__main__': # Create a workbook and add a worksheet. workbook = xlsxwriter.Workbook('sim_infos.xlsx') worksheet = workbook.add_worksheet() # Start from the first cell. Rows and columns are zero indexed. row = 0 col = 0 for sim in params.firebase_store_manager.get_all_sim_infos().stream(): print(sim) sim_pojo = SimInfoPojo.from_firestore_dict(sim.to_dict()) # Iterate over the data and write it out row by row. worksheet.write(row, col, sim_pojo.phone[2:len(sim_pojo.phone)]) worksheet.write(row, col + 1, sim_pojo.ccid) row += 1 workbook.close()