From b773bebac41eabc02b5c40219d7bdca9005cc0fb Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Mon, 22 Jan 2024 22:57:36 +0100 Subject: [PATCH] add ip_country to contact pojo --- src/pojo/contact_pojo.py | 18 ++++++------------ src/utils/excel_reader.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/pojo/contact_pojo.py b/src/pojo/contact_pojo.py index 30cb475..80d2963 100644 --- a/src/pojo/contact_pojo.py +++ b/src/pojo/contact_pojo.py @@ -10,21 +10,16 @@ class ContactPojo: last_name: str first_name: str mail: str - ccid: str - position: int note: str - def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str, - ccid: str = "", - position: int = 0): + def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str): self.phone = str(phone_number).replace(".0", "") self.passport = passport_number self.last_name = last_name self.first_name = first_name - self.ccid = ccid self.mail = mail - self.position = position self.note = "" + self.ip_country = "FR" def to_firestore_dict(self): dest = { @@ -33,17 +28,16 @@ class ContactPojo: u'last_name': self.last_name, u'first_name': self.first_name, u'mail': self.mail, - u'ccid': self.ccid, - u'position': self.position + u'ip_country': self.ip_country } return dest @staticmethod def get_contact_from_error_contact(errorContact: ContactInErrorPojo): - return ContactPojo(phone_number=errorContact.phone, mail=errorContact.mail, ccid=errorContact.ccid, + return ContactPojo(phone_number=errorContact.phone, mail=errorContact.mail, last_name=errorContact.last_name, first_name=errorContact.first_name, - position=errorContact.position, passport_number=errorContact.passport) + passport_number=errorContact.passport) @staticmethod def from_firestore_dict(source): @@ -54,6 +48,6 @@ class ContactPojo: email = source['mail'] last_name = source['last_name'] first_name = source['first_name'] - result = ContactPojo(ccid=ccid, phone_number=phone, passport_number=passport, position=position, mail=email, + result = ContactPojo(phone_number=phone, passport_number=passport, mail=email, last_name=last_name, first_name=first_name) return result diff --git a/src/utils/excel_reader.py b/src/utils/excel_reader.py index 3285e64..91bf41e 100755 --- a/src/utils/excel_reader.py +++ b/src/utils/excel_reader.py @@ -6,7 +6,6 @@ import pandas as pandas import validators as validators import xlsxwriter -from src.config import CONTACT_LIST_FILE from src.db.mongo_manager import MONGO_STORE_MANAGER from src.pojo.contact_pojo import ContactPojo from src.pojo.mail.mail_pojo import MailAddress @@ -29,7 +28,7 @@ def read_links_to_click(file_path): print("error on link " + link) -def read_contacts(file_name=CONTACT_LIST_FILE) -> list: +def read_contacts(file_name) -> list: print("read file " + file_name) contact_list_in_json = pandas.read_excel(file_name).to_json(orient='records') contact_dict_list = json.loads(contact_list_in_json) @@ -43,12 +42,16 @@ def read_contacts(file_name=CONTACT_LIST_FILE) -> list: first_name = name[-1] else: first_name = ''.join(name[1:len(name)]) + ip_country = "FR" + if contact_dict.get('ip_country') is not None: + ip_country = contact_dict['ip_country'] contact = ContactPojo(phone_number=contact_dict['phone'], last_name=last_name, first_name=first_name, passport_number=contact_dict['passport'], mail=contact_dict['email']) + contact.ip_country = ip_country contact_list.append(contact) return contact_list @@ -72,7 +75,7 @@ class ExcelHelper: user_agent_list.append(user_agent_dict['user_agent']) print(user_agent_list) - def check_contact_list(self, file_name=CONTACT_LIST_FILE): + def check_contact_list(self, file_name): contact_list = read_contacts(file_name) for contact in contact_list: if contact.first_name is None or len(contact.first_name) == 0: @@ -99,7 +102,7 @@ class ExcelHelper: contact_list.append(contact) return contact_list - def read_names(self, file_name=CONTACT_LIST_FILE) -> list: + def read_names(self, file_name) -> list: contact_list_in_json = pandas.read_excel(file_name).to_json(orient='records') contact_dict_list = json.loads(contact_list_in_json) contact_list = [] @@ -134,7 +137,7 @@ class ExcelHelper: return contact_list - def read_email_pojo(self, file_name=CONTACT_LIST_FILE) -> list: + def read_email_pojo(self, file_name) -> list: email_info_in_json = pandas.read_excel(file_name).to_json(orient='records') contact_dict_list = json.loads(email_info_in_json) contact_list = []