49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
import json
|
|
|
|
import pandas as pandas
|
|
|
|
from pojo.contact_pojo import ContactPojo
|
|
|
|
|
|
class ExcelHelper:
|
|
|
|
def __init__(self):
|
|
self._df = pandas.Series()
|
|
|
|
def write_to_exel(self, file_name, data_list: list):
|
|
new_df = pandas.Series(data_list)
|
|
self._df = pandas.concat([self._df, new_df])
|
|
self._df.to_excel(file_name)
|
|
|
|
def generate_exel_from_txt(self):
|
|
f = open("../phone_list.txt")
|
|
lines = f.read()
|
|
self.write_to_exel("phone_list.xlsx", lines.split(","))
|
|
ccid_file = open("../ccid_list.txt")
|
|
ccids = ccid_file.read()
|
|
self.write_to_exel("ccid_list.xlsx", ccids.split(","))
|
|
print(lines)
|
|
|
|
# read the contact list from the exel file
|
|
def read_contacts(self) -> list:
|
|
contact_list_in_json = pandas.read_excel(r'./contact.xlsx').to_json(orient='records')
|
|
contact_dict_list = json.loads(contact_list_in_json)
|
|
contact_list = []
|
|
for contact_dict in contact_dict_list:
|
|
name = contact_dict['name'].split(' ')
|
|
first_name = name[0]
|
|
last_name = name[-1]
|
|
contact = ContactPojo(phone_number=contact_dict['phone'],
|
|
last_name=last_name,
|
|
first_name=first_name,
|
|
ccid=contact_dict['ccid'],
|
|
passport_number=contact_dict['passport'],
|
|
mail=contact_dict['email'])
|
|
contact_list.append(contact)
|
|
return contact_list
|
|
|
|
|
|
if __name__ == '__main__':
|
|
helper = ExcelHelper()
|
|
helper.generate_exel_from_txt()
|