Purge_Registres_D-c-s_INSEE/purge-registres-deces-insee/excel_in.py

55 lines
1.7 KiB
Python

"""
Copyright (c) 2020 Sdj Geek
Voir le fichier LICENSE
Classe d'accès aux données du site de l'Église
"""
import os
import pandas as pd
import numpy as np
from membre_base import MembreBase, MembreProvider
class ExcelIn(MembreProvider):
def __init__(self, excel_path):
self.excel_path = excel_path
self.dataframe = None
def __len__(self):
return len(self.dataframe)
class Member(MembreBase):
def __init__(self, provider, row):
super().__init__(provider)
self.r_id = str(row["id"])
self.r_first_name = str(row["first_name"]).strip().split(' ')[0].upper()
self.r_last_name = str(row["last_name"]).strip().split(' ')[0].upper()
self.r_maiden_name = str(row["maiden_name"]).strip().split(' ')[0].upper() if type(row["maiden_name"]) == np.str else None
self.r_annee = str(row["annee"])
self.r_mois = str(row["mois"])
self.r_jour = str(row["jour"])
self.r_ville = "<VIDE>"
self.r_sexe = "F" if str(row["status"]) == "Female" else "M"
def get_name(self):
return os.path.basename(self.excel_path)
def load(self):
self.dataframe = pd.read_excel(self.excel_path, skiprows=[0, 1], usecols="B:E,G:I,K", header=None,
names=["last_name", "first_name", "maiden_name", "id", "jour", "mois", "annee",
"status"])
return len(self.dataframe)
def get_member_list(self):
for index, row in self.dataframe.iterrows():
try:
yield self.Member(self, row)
except ValueError:
print(f"Error with member [{row}]")
continue