aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-10-29 23:28:17 +0100
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-10-29 23:28:17 +0100
commita1926f6b195ccaee7c994848aaf4f70d2fdec976 (patch)
tree4c12fa0ac8c119af1a3826fbd4937a1b442d5919
parent937c1690909f8a8645916fed943ea0506f86634c (diff)
Added what was missing from SDY, still requires extensive testing.
-rwxr-xr-xsgdfi/_decode.py287
-rwxr-xr-xsgdfi/_intranet.py25
2 files changed, 292 insertions, 20 deletions
diff --git a/sgdfi/_decode.py b/sgdfi/_decode.py
index 0606ca4..05071eb 100755
--- a/sgdfi/_decode.py
+++ b/sgdfi/_decode.py
@@ -900,10 +900,17 @@ class Decoder:
""" Decode the HTML operations from a BeautifulSoup decoded
content. """
- people = []
-
parent = tree.find(id = 'ctl00_MainContent__recherche__gvResultats')
- for line in parent.children:
+ elts = []
+
+ # Get the pagination.
+
+ if parent.find(attrs = {'class': 'pagination'}):
+ elts.append(self.__get_html_pagination(parent))
+
+ # Get the people.
+
+ for line in parent.find('tr', attrs = {'class': ['ligne1', 'ligne2']}):
try:
_, name, adh, fct, st, finfct, cp, vil, \
finadh, *_ = line.children
@@ -921,12 +928,8 @@ class Decoder:
except:
continue
- nom = next(name.children).text
- props = nom.split()
-
p.iid = iid
- p.common_name = props[0]
- p.first_name = props[-1]
+ p.name = next(name.children).text
# Code d'adhérent, fonction, structure associée,
# période d'adhésion. TODO
@@ -945,8 +948,10 @@ class Decoder:
# fonction.
try:
- code = next(adh.children).text
+ p.code = next(adh.children).text
fin_adhesion = next(finadh.children).text
+
+ #p.membership_end = fin_adhesion? TODO
except:
code = None
@@ -957,19 +962,275 @@ class Decoder:
finfonction = None
structure = next(st.children).text
+ p.function = fonction
+ #p.function_end = finfonction? TODO
+ #p.structure = structure? TODO
+
# Commune de résidence.
code_postal = next(cp.children).text
ville = next(vil.children).text
- p.address.municipality.name = ville
- p.address.municipality.postal_code = code_postal
+ p.postal_code = code_postal
+ p.town = ville
# Ajout au tableau.
- people.append(p)
+ elts.append(p)
+
+ return elts
+
+ def _decode_html_intranet_person_summary_fragment(self, tree):
+ """ Decode the HTML summary page fragment for a person. """
+
+ parent = tree.find(id = 'ctl00_ctl00_MainContent_TabsContent_' \
+ 'TabContainerResumeAdherent__tabResume')
+ rpre = 'ctl00_ctl00_MainContent_TabsContent_' \
+ 'TabContainerResumeAdherent__tabResume__resume__'
+
+ def checked(x):
+ try:
+ return x['checked'] != 'no'
+ except:
+ return False
+
+ p = _Adherent()
+
+ # IID (from the print button).
+
+ iid = tree.find(id = '_btnPrint')
+ iid = iid['onclick']
+ iid = iid[iid.find('ResumeAdherent.aspx?id=') + 23:]
+ iid = iid[:iid.find('&')]
+ p.iid = iid
+
+ # Titre (nom complet de la personne).
+ # Ce titre est au format "M. DUPONT FRANCOIS JOSEPH".
+
+ titre = tree.find(id = 'ctl00_ctl00__divTitre')
+ p.name = titre.text
+
+ # Onglet "Personne" : code d'adhérent. TODO
+
+ adh = parent.find(id = f'{rpre}lblCodeAdherent')
+ p.code = adh.text
+
+ # Onglet "Personne" : code et nom de la structure associée. TODO
+
+ st = parent.find(id = f'{rpre}hlStructure')
+ stid = _parse_qs(_urlparse(st['href']).query)['id'][0]
+ stid = _b64decode(stid)
+ stnm = st.text
+
+ # Onglet "Personne" : fonctions primaire et secondaires. TODO
+
+ fct = parent.find(id = f'{rpre}lblFonction')
+ fct = fct.text
+
+ sec = parent.find(id = f'{rpre}lblFonctionsSecondaires')
+ sec = sec.text
+
+ # Onglet "Personne" : statut actuel. TODO
+
+ sta = parent.find(id = f'{rpre}lblTypeInscription')
+ sta = sta.text
+
+ # Onglet "Personne" : doublon de. TODO
+
+ dbl = parent.find(id = f'{rpre}hlPersonneDoublonDe')
+ dbl = dbl.text
+
+ # Onglet "Personne" : début et fin de la fonction courante. TODO
+
+ deb = parent.find(id = f'{rpre}lblDebutFonction')
+ deb = deb.text
+
+ fin = parent.find(id = f'{rpre}lblFinFonction')
+ fin = fin.text
+
+ # Onglet "Personne" : nom de jeune fille.
+
+ nomn = parent.find(id = f'{rpre}modeleIndividu__lblNomJeuneFille2')
+ p.name.last = nomn.text
+
+ # Onglet "Personne" : adresse postale. TODO
+
+ lines = []
+ for i in _count(1):
+ try:
+ aid = f'{rpre}modeleIndividu__resumeAdresse__lbLigne{i}'
+ al = parent.find(id = aid)
+ assert al != None
+ except:
+ break
+ lines.append(al.text.strip())
+
+ cp = parent.find(id = f'{rpre}modeleIndividu__resumeAdresse_' \
+ '_lbCodePostal')
+ vil = parent.find(id = f'{rpre}modeleIndividu__resumeAdresse__lbVille')
+ pays = parent.find(id = f'{rpre}modeleIndividu__resumeAdresse__lbPays')
+
+ #p.address.text = '\n'.join(lines)
+ #p.address.city.name = vil.text.strip()
+ #p.address.city.postal_code = cp.text.strip()
+ #p.address.city.country = pays.text.strip()
+
+ # Onglet "Personne" : NPAI. TODO
+
+ npai = parent.find(id = f'{rpre}modeleIndividu__lblNpai')
+ npai = npai.text
+
+ # Onglet "Personne" : numéros de téléphone utilisés. TODO
+
+ def phone(x):
+ if x[0] == '0':
+ x = x[1:]
+ return '+33' + x
+
+ dph = parent.find(id = f'{rpre}modeleIndividu__lblTelephoneDomicile')
+ dph = dph.text
+ pph = parent.find(id = f'{rpre}modeleIndividu__lblTelephoneBureau')
+ pph = pph.text
+ cph1 = parent.find(id = f'{rpre}modeleIndividu__lblTelephonePortable1')
+ cph1 = cph1.text
+ cph2 = parent.find(id = f'{rpre}modeleIndividu__lblTelephonePortable2')
+ cph2 = cph2.text
+
+ # Onglet "Personne" : adresses de courriel utilisées. TODO
+
+ iem = parent.find(id = f'{rpre}modeleIndividu__hlCourrielPersonnel')
+ iem = iem.text
+ pem = parent.find(id = f'{rpre}modeleIndividu_' \
+ '_hlCourrielProfessionnel')
+ pem = pem.text
+
+ # Onglet "Personne" : date de naissance.
+
+ bd = parent.find(id = f'{rpre}modeleIndividu__lblDateNaissance')
+ bd = bd.text
+
+ mday, mon, year = map(int, bd.split('/'))
+ p.birth_date = Date(year, mon, mday)
+
+ # Onglet "Personne" : commune de naissance.
+
+ bpp = parent.find(id = f'{rpre}modeleIndividu__lbCPNaissance')
+ bpp = bpp.text
+ bpn = parent.find(id = f'{rpre}modeleIndividu__lbCommuneNaissance')
+ bpn = bpn.text
+ bpi = parent.find(id = f'{rpre}modeleIndividu__lbCodeInsee')
+ bpi = bpi.text
+
+ p.birth_town = bpn
+ p.birth_postal_code = bpp
+ p.birth_insee_code = bpi
+
+ # Onglet "Personne" : profession actuelle. TODO
+
+ pro = parent.find(id = f'{rpre}modeleIndividu__lblProfession')
+ pro = pro.text
+
+ # Onglet "Personne" : régime d'allocations et numéro
+ # d'allocataire. TODO
+
+ nal = parent.find(id = f'{rpre}modeleIndividu__lblNumeroAllocataire')
+ nal = nal.text
+
+ p.allocations.number = (None, nal)[nal != '.']
+
+ caf = parent.find(id = f'{rpre}modeleIndividu__cbRegimeCAF')
+ msa = parent.find(id = f'{rpre}modeleIndividu__cbRegimeMSA')
+ mar = parent.find(id = f'{rpre}modeleIndividu__cbRegimeMaritime')
+ aut = parent.find(id = f'{rpre}modeleIndividu__cbRegimeAutre')
+ aun = parent.find(id = f'{rpre}modeleIndividu__lblRegimeAllocataire')
+ aun = aun.text
+
+ if checked(caf) or checked(mar):
+ p.allocations.regime = AL_GEN
+ elif checked(msa):
+ p.allocations.regime = AL_MSA
+ else:
+ p.allocations.regime = AL_OTH
+ p.allocations.regime_name = ("", aun)[aun != '.']
+
+ # Onglet "Personne" : autorise les interventions chirurgicales.
+
+ med = parent.find(id = f'{rpre}cbAutorisationInterventionChirurgicale')
+ p.medical_surgical_measures = checked(med)
+
+ # Onglet "Personne" : droit à l'image accordé à l'association.
+
+ img = parent.find(id = f'{rpre}cbAutorisationImage')
+ p.image_rights = checked(img)
+
+ # Onglet "Personne" : assurance chef de famille.
+
+ civ = parent.find(id = f'{rpre}cbAssuranceRc')
+ p.civil_liability_insurance = checked(civ)
+
+ # Onglet "Personne" : personne à contacter en cas d'urgence. TODO
+
+ unom = parent.find(id = f'{rpre}lblNomUrgence')
+ unom = unom.text
+
+ upren = parent.find(id = f'{rpre}lblPrenomUrgence')
+ upren = upren.text
+
+ unum = parent.find(id = f'{rpre}lblTelephoneUrgence')
+ unum = unum.text
+
+ return p
+
+ def _decode_html_intranet_person_family_fragment(self, tree):
+ """ Decode the HTML family page fragment for an adherent. """
+
+ parent = tree.find(id = 'ctl00_ctl00_MainContent_TabsContent_' \
+ 'TabContainerResumeAdherent__tabFamille__famille__lblFamille')
+
+ # IID (from the print button). TODO
+
+ iid = tree.find(id = '_btnPrint')
+ iid = iid['onclick']
+ iid = iid[iid.find('ResumeAdherent.aspx?id=') + 23:]
+ iid = iid[:iid.find('&')]
+
+ # Titre (nom complet de la personne). TODO
+ # Ce titre est au format "M. DUPONT FRANCOIS JOSEPH".
+
+ titre = tree.find(id = 'ctl00_ctl00__divTitre')
+
+ # Onglet "Famille" : relations. TODO
+ #
+ # Ici, on a du <a><br><a><br>…<a><br>, où le `href` contient l'URL de
+ # l'adhérent sous forme absolue mais relative au site, i.e.
+ #
+ # /Specialisation/Sgdf/adherents/ResumeAdherent.aspx?id=<b64 id>
+ #
+ # et où le texte contient le nom de l'adhérent sous le format
+ # NOM PRÉNOM.
+ #
+ # S'il n'y a pas de rattachements familiaux, on a simplement un
+ #
+ # <span class="non_dispo">Pas de rattachement familial</span>.
+
+ fam = []
+
+ it = parent.children
+ while True:
+ try:
+ link = next(it)
+ next(it)
+ assert link.name == 'a'
+ except:
+ break
+
+ famid = _parse_qs(_urlparse(link['href']).query)['id'][0]
+ famid = _b64decode(famid)
+ famnm = link.text
+
+ fam.append((famid, famnm))
- return people
+ return []
def _decode_html_intranet_calendar_month_fragment(self, tree):
""" Decode the HTML page for a calendar month from a
diff --git a/sgdfi/_intranet.py b/sgdfi/_intranet.py
index 8804cbe..6866b56 100755
--- a/sgdfi/_intranet.py
+++ b/sgdfi/_intranet.py
@@ -553,7 +553,7 @@ class IntranetSession(AnonymousIntranetSession):
raise _InvalidCredentialsError(user = self.__user, pw = pw)
# ---
- # Obtain objects.
+ # Interact with operations.
# ---
def _get_ops_page(self, ent_type, ent_iid, page):
@@ -611,6 +611,10 @@ class IntranetSession(AnonymousIntranetSession):
return activities
+ # ---
+ # Interact with places.
+ # ---
+
def get_place(self, pl_id):
""" Get a place's data. """
@@ -621,9 +625,12 @@ class IntranetSession(AnonymousIntranetSession):
# Récupération et décodage de la page.
# XXX: hack pour l'iid. Le récupérer directement sur la page ?
- elts = self.get_page(path, hint = 'place')
- pl.iid = iid
- return pl
+ result = self.get_page(path, hint = 'intranet_place')
+ return result
+
+ # ---
+ # Interact with structures.
+ # ---
def _get_structures_page(self, page, st_name, st_dept, st_type, st_spe,
st_sta):
@@ -733,20 +740,24 @@ class IntranetSession(AnonymousIntranetSession):
state['ActiveTabIndex'] = 1
args[stname] = _jsondumps(state)
st = self.get_page(path, args, method = self.METHOD_FORM,
- hint = "structure_summary")
+ hint = "intranet_structure_summary")
# Récupération de l'onglet "Hiérarchie".
state['ActiveTabIndex'] = 0
args[stname] = _jsondumps(state)
st_updates = self.get_page(path, args, method = self.METHOD_FORM,
- hint = "structure_hierarchy")
+ hint = "intranet_structure_hierarchy")
# FIXME: feed with iid
st.iid = iid
return st
+ # ---
+ # Interact with events.
+ # ---
+
def get_events(self, year = 2018, month = 6):
""" Get events in the calendar. """
@@ -785,6 +796,6 @@ class IntranetSession(AnonymousIntranetSession):
'_ddStructure': '1061745',
'_hidCodeStructure': '119101231'}}}},
method = self.METHOD_AJAX,
- hint = 'calendar_month')
+ hint = 'intranet_calendar_month')
# End of file.