Merge branch 'master' into feature/gui
This commit is contained in:
+2
-71
@@ -1,15 +1,13 @@
|
||||
import datetime
|
||||
|
||||
import firebase_admin
|
||||
import xlsxwriter as xlsxwriter
|
||||
from firebase_admin import credentials, firestore
|
||||
|
||||
import definitions
|
||||
import params
|
||||
from pojo.MailPojo import MailPojo
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
from pojo.SimInfoPojo import SimInfoPojo
|
||||
from pojo.contact_pojo import ContactPojo
|
||||
from utils.excel_reader import ExcelHelper
|
||||
from utils.operator import Operator
|
||||
|
||||
ERROR_COLLECTION_NAME = "error_items"
|
||||
CONTACT_COLLECTION_NAME = "contact_list"
|
||||
@@ -17,9 +15,6 @@ MAIL_COLLECTION_NAME = "mail_list"
|
||||
SIM_INFOS = "sim_infos"
|
||||
TIMEOUT = "timeout_items"
|
||||
|
||||
excel_reader = ExcelHelper()
|
||||
|
||||
|
||||
class DataManager:
|
||||
batch_size = 20
|
||||
|
||||
@@ -28,9 +23,6 @@ class DataManager:
|
||||
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
|
||||
@@ -83,60 +75,6 @@ class DataManager:
|
||||
coll_ref = self._db.collection(SIM_INFOS)
|
||||
self._delete_collection(coll_ref, self.batch_size)
|
||||
|
||||
## 读取数据库中的sim卡信息,然后写到sim_infos.xlsx文件中
|
||||
def save_to_excel(self):
|
||||
# Start from the first cell. Rows and columns are zero indexed.
|
||||
self._contact_list = excel_reader.read_contacts()
|
||||
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
|
||||
else:
|
||||
sim_pojo.email = ""
|
||||
sim_pojo.name = ""
|
||||
sim_pojo.passport = ""
|
||||
sim_info_list.append(sim_pojo)
|
||||
row = 0
|
||||
col = 0
|
||||
# Create a workbook and add a worksheet.
|
||||
workbook = xlsxwriter.Workbook(definitions.ROOT_DIR + "/docs/sim_infos.xlsx")
|
||||
worksheet = workbook.add_worksheet()
|
||||
worksheet.write(row, 0, "phone")
|
||||
worksheet.write(row, 1, "ccid")
|
||||
worksheet.write(row, 2, "name")
|
||||
worksheet.write(row, 3, "passport")
|
||||
worksheet.write(row, 4, "email")
|
||||
worksheet.write(row, 5, "position")
|
||||
worksheet.write(row, 6, "operator")
|
||||
row = row + 1
|
||||
for info in sim_info_list:
|
||||
# Iterate over the data and write it out row by row.
|
||||
if info.operator == Operator.LYCAMOBILE.value:
|
||||
worksheet.write(row, col, info.phone[2:len(info.phone)])
|
||||
else:
|
||||
worksheet.write(row, col, info.phone)
|
||||
worksheet.write(row, col + 1, info.ccid)
|
||||
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)
|
||||
worksheet.write(row, col + 6, info.operator)
|
||||
row += 1
|
||||
workbook.close()
|
||||
|
||||
def upload_contact_list_to_cloud(self):
|
||||
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
|
||||
@@ -148,10 +86,3 @@ class DataManager:
|
||||
mail_pojo = MailPojo.from_firestore_dict(mail.to_dict())
|
||||
mail_list.append(mail_pojo)
|
||||
return mail_list
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# params.firebase_store_manager.find_appointment_detail_via_phone(str(datetime.date.today()), 613467904)
|
||||
params.firebase_store_manager.save_to_excel()
|
||||
# params.firebase_store_manager.clear_all_sim_info()
|
||||
# print(params.firebase_store_manager.get_mail_list())
|
||||
|
||||
Reference in New Issue
Block a user