2020-07-17 21:49:45 +02:00
|
|
|
"""
|
|
|
|
Copyright (c) 2020 Sdj Geek
|
|
|
|
Voir le fichier LICENSE
|
|
|
|
|
|
|
|
Classe d'accès aux données du site de l'Église
|
2020-06-09 00:16:00 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2020-06-07 00:52:15 +02:00
|
|
|
import requests
|
2020-06-15 21:05:27 +02:00
|
|
|
import browser_cookie3
|
2020-06-07 00:52:15 +02:00
|
|
|
|
2020-07-18 16:18:17 +02:00
|
|
|
from membre_base import MembreBase, MembreProvider
|
2020-06-07 00:52:15 +02:00
|
|
|
|
2020-06-09 00:16:00 +02:00
|
|
|
|
2020-07-18 16:18:17 +02:00
|
|
|
class SiteEglise(MembreProvider):
|
|
|
|
|
2020-07-18 16:49:02 +02:00
|
|
|
def __init__(self, unite, cookie_path=None):
|
2020-06-15 21:05:27 +02:00
|
|
|
"""
|
2020-07-18 16:49:02 +02:00
|
|
|
:param unite: numéro de l'unité (paroisse, branche)
|
2020-06-15 21:05:27 +02:00
|
|
|
:param cookie_path: chemin vers le répertoire où inscrire les fichiers de sortie
|
|
|
|
"""
|
2020-07-18 16:49:02 +02:00
|
|
|
self.unite = unite
|
2020-06-15 21:05:27 +02:00
|
|
|
self.cookie_jar = browser_cookie3.firefox(cookie_file=cookie_path)
|
2020-07-18 16:18:17 +02:00
|
|
|
self.as_json = None
|
2020-06-07 00:52:15 +02:00
|
|
|
|
2020-07-18 16:18:17 +02:00
|
|
|
def __len__(self):
|
|
|
|
return len(self.as_json)
|
2020-06-07 00:52:15 +02:00
|
|
|
|
2020-07-18 16:18:17 +02:00
|
|
|
class Membre(MembreBase):
|
2020-06-09 00:16:00 +02:00
|
|
|
|
2020-07-18 16:18:17 +02:00
|
|
|
def __init__(self, provider, data):
|
|
|
|
super().__init__(provider)
|
|
|
|
self.completed = False
|
|
|
|
# Données fournies
|
|
|
|
self.r_id = data['legacyCmisId']
|
2020-07-18 16:49:02 +02:00
|
|
|
self.r_last_name, self.r_first_name = data['nameListPreferredLocal'].upper().split(',')
|
2020-07-18 16:18:17 +02:00
|
|
|
self.r_last_name = self.r_last_name.strip().split(' ')[0]
|
|
|
|
self.r_first_name = self.r_first_name.strip().split(' ')[0]
|
|
|
|
self.r_annee, self.r_mois, self.r_jour = data['birth']['date']['date'].split('-')
|
|
|
|
self.r_sexe = data['sex']
|
|
|
|
# Rechercher le nom de jeune fille si besoin
|
|
|
|
if data['isSpouse']:
|
|
|
|
self.complete()
|
|
|
|
|
|
|
|
def complete(self):
|
|
|
|
if not self.completed:
|
|
|
|
member_profile = self.provider.get_member_profile(self.r_id)
|
|
|
|
self.r_maiden_name = member_profile['individual']['maidenNameGroup']['name1']['family']
|
|
|
|
self.r_ville = member_profile['individual']['birthPlace']
|
|
|
|
if not self.r_ville:
|
|
|
|
self.r_ville = "<VIDE>"
|
|
|
|
self.completed = True
|
|
|
|
|
|
|
|
def set_insee(self, insee):
|
|
|
|
self.complete()
|
|
|
|
super().set_insee(insee)
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return f"Unité_{self.unite}"
|
|
|
|
|
|
|
|
def load(self):
|
2020-06-15 21:05:27 +02:00
|
|
|
r = requests.get('https://lcr.churchofjesuschrist.org/services/umlu/report/member-list',
|
2020-07-18 16:18:17 +02:00
|
|
|
params={'lang': "fra", 'unitNumber': self.unite},
|
2020-06-16 23:27:47 +02:00
|
|
|
headers={'Accept': "application/json"},
|
|
|
|
cookies=self.cookie_jar)
|
2020-06-15 21:05:27 +02:00
|
|
|
r.raise_for_status()
|
2020-07-18 16:18:17 +02:00
|
|
|
self.as_json = r.json()
|
|
|
|
return len(self.as_json)
|
|
|
|
|
|
|
|
def get_member_list(self):
|
|
|
|
"""Recevoir la liste des membres
|
|
|
|
|
2020-07-18 16:49:02 +02:00
|
|
|
|
2020-07-18 16:18:17 +02:00
|
|
|
:returns: la liste des membres sous forme d'objet JSON
|
|
|
|
|
|
|
|
"""
|
|
|
|
for member in self.as_json:
|
|
|
|
try:
|
|
|
|
yield self.Membre(self, member)
|
|
|
|
except ValueError:
|
|
|
|
print(f"Error with member [{member['nameListPreferredLocal']}, {member['birth']['date']['date']}]")
|
|
|
|
continue
|
2020-06-09 00:16:00 +02:00
|
|
|
|
2020-06-15 21:05:27 +02:00
|
|
|
def get_member_profile(self, member_id):
|
|
|
|
"""Recevoir les informations sur un membre
|
|
|
|
|
|
|
|
:param member_id: ID du membre
|
|
|
|
:returns: les informations sur le membre sous forme d'objet JSON
|
|
|
|
|
|
|
|
"""
|
|
|
|
r = requests.get(f'https://lcr.churchofjesuschrist.org/records/member-profile/service/{member_id}',
|
|
|
|
params={'lang': "fra"},
|
|
|
|
headers={'Accept': "application/json",
|
2020-06-16 23:27:47 +02:00
|
|
|
'Referer': f"https://lcr.churchofjesuschrist.org/records/member-profile/{member_id}?lang=fra"},
|
|
|
|
cookies=self.cookie_jar)
|
2020-06-15 21:05:27 +02:00
|
|
|
r.raise_for_status()
|
|
|
|
return r.json()
|