Merge branch 'master' into feature/gui

This commit is contained in:
2022-05-12 11:56:04 +02:00
3 changed files with 10 additions and 73 deletions
+2 -71
View File
@@ -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())
+8 -1
View File
@@ -4,6 +4,8 @@ from typing import Union
from dataclasses_json import dataclass_json
import definitions
class PublishType(Enum):
SUCCESS = "SUCCESS"
@@ -26,6 +28,7 @@ class ReserveResultPojo:
slot_position = None
sim_position = None
ccid: str = ""
source_from: str = definitions.LOG_SOURCE
@staticmethod
def from_firestore_dict(source):
@@ -43,6 +46,9 @@ class ReserveResultPojo:
if 'accepted' in source:
accepted = source['accepted']
result.accepted = accepted
if 'source' in source:
source_from = source['source']
result.source_from = source_from
if 'sim_position' in source:
sim_position = source['sim_position']
result.sim_position = sim_position
@@ -71,7 +77,8 @@ class ReserveResultPojo:
u'url': self.url,
u'sim_position': self.sim_position,
u'slot_position': self.slot_position,
u'ccid': self.ccid
u'ccid': self.ccid,
u'source_from': self.source_from
}
return dest
-1
View File
@@ -34,7 +34,6 @@ def get_random_wait_time() -> float:
class Tls(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
print("Create playwright instance in Thread", threading.current_thread().name)
class CommandorPage: