40 lines
1.3 KiB
Python
40 lines
1.3 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_phone(self, phone_number):
|
|
new_df = pandas.Series([phone_number])
|
|
self._df = pandas.concat([self._df, new_df])
|
|
self._df.to_excel("phone_list.xlsx")
|
|
|
|
# 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.write_phone("88649614591")
|