Commit d71aedcf by Nicolas Joyard

Date modif: maj job AMO

parent 2fbd0925
Showing with 72 additions and 47 deletions
......@@ -27,106 +27,126 @@ class ImportAMOJob(BaseANJob):
def save_acteur(self, json):
self.current = u'Acteur %s' % json['uid']['#text']
acteur, _ = self.get_or_create(Acteur, id=json['uid']['#text'])
ec = json['etatCivil']
id = ec['ident']
acteur.civilite = id['civ']
acteur.nom = id['nom']
acteur.prenom = id['prenom']
nais = ec['infoNaissance']
acteur.date_naissance = self.parse_date(nais['dateNais'])
acteur.ville_naissance = nais['villeNais']
acteur.dept_naissance = nais['depNais']
acteur.pays_naissance = nais['paysNais']
data = {
'civilite': id['civ'],
'date_deces': None,
'date_naissance': self.parse_date(nais['dateNais']),
'dept_naissance': nais['depNais'],
'nom': id['nom'],
'pays_naissance': nais['paysNais'],
'prenom': id['prenom'],
'profession': None,
'profession_cat_insee': None,
'profession_fam_insee': None,
'ville_naissance': nais['villeNais'],
}
if ec.get('dateDeces', None):
acteur.date_deces = self.parse_date(ec['dateDeces'])
data['date_deces'] = self.parse_date(ec['dateDeces'])
if 'profession' in json:
pro = json['profession']
acteur.profession = pro['libelleCourant']
acteur.profession_cat_insee = pro['socProcINSEE']['catSocPro']
acteur.profession_fam_insee = pro['socProcINSEE']['famSocPro']
data['profession'] = pro['libelleCourant']
data['profession_cat_insee'] = pro['socProcINSEE']['catSocPro']
data['profession_fam_insee'] = pro['socProcINSEE']['famSocPro']
acteur = self.save(Acteur, json['uid']['#text'], data)
for mandat_json in json['mandats']['mandat']:
self.save_mandat(acteur, mandat_json)
def save_mandat(self, acteur, json):
self.current = u'Mandat %s' % json['uid']
mandat, _ = self.get_or_create(Mandat, id=json['uid'])
mandat.acteur = acteur
if isinstance(json['organes']['organeRef'], basestring):
organe_refs = [json['organes']['organeRef']]
else:
organe_refs = json['organes']['organeRef']
mandat.organes = [self.get_cached(Organe, ref) for ref in organe_refs]
data = {
'acteur': acteur,
'date_debut': self.parse_date(json['dateDebut']),
'date_fin': None,
'date_publication': None,
'election_cause': None,
'election_circo': None,
'election_dept': None,
'election_dept_num': None,
'election_region': None,
'libelle': None,
'nomination_principale': json['nominPrincipale'] == '1',
'organes': [self.save(Organe, ref) for ref in organe_refs],
'preseance': None,
'qualite': json['infosQualite']['codeQualite'],
'url_hatvp': None,
}
mandat.date_debut = self.parse_date(json['dateDebut'])
if json.get('datePublication', None):
mandat.date_publication = self.parse_date(json['datePublication'])
if json.get('dateFin', None):
mandat.date_fin = self.parse_date(json['dateFin'])
data['date_publication'] = self.parse_date(json['datePublication'])
mandat.qualite = json['infosQualite']['codeQualite']
mandat.nomination_principale = json['nominPrincipale'] == '1'
if json.get('dateFin', None):
data['date_fin'] = self.parse_date(json['dateFin'])
if json.get('preseance', None):
mandat.preseance = int(json['preseance'])
data['preseance'] = int(json['preseance'])
if json.get('libelle', None):
mandat.libelle = json['libelle']
data['libelle'] = json['libelle']
if json.get('InfosHorsSIAN', None):
if json['InfosHorsSIAN'].get('HATVP_URI', None):
mandat.url_hatvp = json['InfosHorsSIAN']['HATVP_URI']
data['url_hatvp'] = json['InfosHorsSIAN']['HATVP_URI']
if 'election' in json:
el = json['election']
li = el['lieu']
mandat.election_region = li['region']
mandat.election_dept = li['departement']
mandat.election_dept_num = li['numDepartement']
mandat.election_cause = el['causeMandat']
data['election_region'] = li['region']
data['election_dept'] = li['departement']
data['election_dept_num'] = li['numDepartement']
data['election_cause'] = el['causeMandat']
if li['numCirco']:
mandat.election_circo = int(li['numCirco'])
data['election_circo'] = int(li['numCirco'])
mandat = self.save(Mandat, json['uid'], data)
def save_organe(self, json):
self.current = u'Organe %s' % json['uid']
organe = self.get_cached(Organe, json['uid'])
organe.type = json['codeType']
organe.libelle = json['libelle']
organe.libelle_court = json['libelleAbrege']
organe.abbreviation = json['libelleAbrev']
data = {
'abbreviation': json['libelleAbrev'],
'date_debut': None,
'date_fin': None,
'legislature': None,
'libelle': json['libelle'],
'libelle_court': json['libelleAbrege'],
'regime': None,
'type': json['codeType'],
}
if json['viMoDe']['dateDebut']:
organe.date_debut = self.parse_date(json['viMoDe']['dateDebut'])
else:
organe.date_debut = None
data['date_debut'] = self.parse_date(json['viMoDe']['dateDebut'])
if json['viMoDe']['dateFin']:
organe.date_fin = self.parse_date(json['viMoDe']['dateFin'])
else:
organe.date_fin = None
data['date_fin'] = self.parse_date(json['viMoDe']['dateFin'])
if json.get('regime', None):
organe.regime = self.get_cached(Regime, json['regime'])
data['regime'] = self.save(Regime, json['regime'])
if json.get('legislature', None):
organe.legislature = self.get_cached(Legislature,
data['legislature'] = self.save(Legislature,
int(json['legislature']))
if organe.regime:
organe.legislature.regime = organe.regime
if data['regime']:
data['legislature'].regime = data['regime']
organe = self.save(Organe, json['uid'], data)
def run(app, force=False, file=None):
......
......@@ -41,6 +41,7 @@ class Regime(db.Model):
__tablename__ = 'regimes'
query_class = SearchableQuery
_last_modified = db.Column(db.DateTime)
id = db.Column(db.Integer, primary_key=True)
nom = db.Column(db.Unicode)
......@@ -54,6 +55,7 @@ class Regime(db.Model):
class Legislature(db.Model):
__tablename__ = 'legislatures'
_last_modified = db.Column(db.DateTime)
id = db.Column(db.Integer, primary_key=True)
date_debut = db.Column(db.Date)
date_fin = db.Column(db.Date)
......@@ -78,6 +80,7 @@ class Organe(db.Model):
__tablename__ = 'organes'
query_class = SearchableQuery
_last_modified = db.Column(db.DateTime)
id = db.Column(db.Unicode, primary_key=True)
type = db.Column(db.Unicode)
libelle = db.Column(db.Unicode)
......@@ -109,6 +112,7 @@ class Mandat(db.Model):
__tablename__ = 'mandats'
query_class = SearchableQuery
_last_modified = db.Column(db.DateTime)
id = db.Column(db.Unicode, primary_key=True)
date_debut = db.Column(db.Date)
......@@ -146,6 +150,7 @@ class Acteur(db.Model):
__tablename__ = 'acteurs'
query_class = SearchableQuery
_last_modified = db.Column(db.DateTime)
id = db.Column(db.Unicode, primary_key=True)
civilite = db.Column(db.Unicode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment