2020-07-18 16:49:02 +02:00
|
|
|
"""
|
|
|
|
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
|
2020-07-29 09:56:37 +02:00
|
|
|
import numpy as np
|
2020-07-18 16:49:02 +02:00
|
|
|
|
|
|
|
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)
|
2020-07-29 09:56:37 +02:00
|
|
|
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"
|
2020-07-18 16:49:02 +02:00
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return os.path.basename(self.excel_path)
|
|
|
|
|
|
|
|
def load(self):
|
2020-07-29 09:56:37 +02:00
|
|
|
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"])
|
2020-07-18 16:49:02 +02:00
|
|
|
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
|