Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
parlapi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Guillot
parlapi
Commits
d71aedcf
Commit
d71aedcf
authored
Feb 10, 2017
by
Nicolas Joyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Date modif: maj job AMO
parent
2fbd0925
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
47 deletions
+72
-47
parlapi/jobs/an_amo.py
parlapi/jobs/an_amo.py
+67
-47
parlapi/models.py
parlapi/models.py
+5
-0
No files found.
parlapi/jobs/an_amo.py
View file @
d71aedcf
...
@@ -27,106 +27,126 @@ class ImportAMOJob(BaseANJob):
...
@@ -27,106 +27,126 @@ class ImportAMOJob(BaseANJob):
def
save_acteur
(
self
,
json
):
def
save_acteur
(
self
,
json
):
self
.
current
=
u'Acteur %s'
%
json
[
'uid'
][
'#text'
]
self
.
current
=
u'Acteur %s'
%
json
[
'uid'
][
'#text'
]
acteur
,
_
=
self
.
get_or_create
(
Acteur
,
id
=
json
[
'uid'
][
'#text'
])
ec
=
json
[
'etatCivil'
]
ec
=
json
[
'etatCivil'
]
id
=
ec
[
'ident'
]
id
=
ec
[
'ident'
]
acteur
.
civilite
=
id
[
'civ'
]
acteur
.
nom
=
id
[
'nom'
]
acteur
.
prenom
=
id
[
'prenom'
]
nais
=
ec
[
'infoNaissance'
]
nais
=
ec
[
'infoNaissance'
]
acteur
.
date_naissance
=
self
.
parse_date
(
nais
[
'dateNais'
])
data
=
{
acteur
.
ville_naissance
=
nais
[
'villeNais'
]
'civilite'
:
id
[
'civ'
],
acteur
.
dept_naissance
=
nais
[
'depNais'
]
'date_deces'
:
None
,
acteur
.
pays_naissance
=
nais
[
'paysNais'
]
'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
):
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
:
if
'profession'
in
json
:
pro
=
json
[
'profession'
]
pro
=
json
[
'profession'
]
acteur
.
profession
=
pro
[
'libelleCourant'
]
data
[
'profession'
]
=
pro
[
'libelleCourant'
]
acteur
.
profession_cat_insee
=
pro
[
'socProcINSEE'
][
'catSocPro'
]
data
[
'profession_cat_insee'
]
=
pro
[
'socProcINSEE'
][
'catSocPro'
]
acteur
.
profession_fam_insee
=
pro
[
'socProcINSEE'
][
'famSocPro'
]
data
[
'profession_fam_insee'
]
=
pro
[
'socProcINSEE'
][
'famSocPro'
]
acteur
=
self
.
save
(
Acteur
,
json
[
'uid'
][
'#text'
],
data
)
for
mandat_json
in
json
[
'mandats'
][
'mandat'
]:
for
mandat_json
in
json
[
'mandats'
][
'mandat'
]:
self
.
save_mandat
(
acteur
,
mandat_json
)
self
.
save_mandat
(
acteur
,
mandat_json
)
def
save_mandat
(
self
,
acteur
,
json
):
def
save_mandat
(
self
,
acteur
,
json
):
self
.
current
=
u'Mandat %s'
%
json
[
'uid'
]
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
):
if
isinstance
(
json
[
'organes'
][
'organeRef'
],
basestring
):
organe_refs
=
[
json
[
'organes'
][
'organeRef'
]]
organe_refs
=
[
json
[
'organes'
][
'organeRef'
]]
else
:
else
:
organe_refs
=
json
[
'organes'
][
'organeRef'
]
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
):
if
json
.
get
(
'datePublication'
,
None
):
mandat
.
date_publication
=
self
.
parse_date
(
json
[
'datePublication'
])
data
[
'date_publication'
]
=
self
.
parse_date
(
json
[
'datePublication'
])
if
json
.
get
(
'dateFin'
,
None
):
mandat
.
date_fin
=
self
.
parse_date
(
json
[
'dateFin'
])
mandat
.
qualite
=
json
[
'infosQualite'
][
'codeQualite'
]
if
json
.
get
(
'dateFin'
,
None
):
mandat
.
nomination_principale
=
json
[
'nominPrincipale'
]
==
'1'
data
[
'date_fin'
]
=
self
.
parse_date
(
json
[
'dateFin'
])
if
json
.
get
(
'preseance'
,
None
):
if
json
.
get
(
'preseance'
,
None
):
mandat
.
preseance
=
int
(
json
[
'preseance'
])
data
[
'preseance'
]
=
int
(
json
[
'preseance'
])
if
json
.
get
(
'libelle'
,
None
):
if
json
.
get
(
'libelle'
,
None
):
mandat
.
libelle
=
json
[
'libelle'
]
data
[
'libelle'
]
=
json
[
'libelle'
]
if
json
.
get
(
'InfosHorsSIAN'
,
None
):
if
json
.
get
(
'InfosHorsSIAN'
,
None
):
if
json
[
'InfosHorsSIAN'
].
get
(
'HATVP_URI'
,
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
:
if
'election'
in
json
:
el
=
json
[
'election'
]
el
=
json
[
'election'
]
li
=
el
[
'lieu'
]
li
=
el
[
'lieu'
]
mandat
.
election_region
=
li
[
'region'
]
data
[
'election_region'
]
=
li
[
'region'
]
mandat
.
election_dept
=
li
[
'departement'
]
data
[
'election_dept'
]
=
li
[
'departement'
]
mandat
.
election_dept_num
=
li
[
'numDepartement'
]
data
[
'election_dept_num'
]
=
li
[
'numDepartement'
]
mandat
.
election_cause
=
el
[
'causeMandat'
]
data
[
'election_cause'
]
=
el
[
'causeMandat'
]
if
li
[
'numCirco'
]:
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
):
def
save_organe
(
self
,
json
):
self
.
current
=
u'Organe %s'
%
json
[
'uid'
]
self
.
current
=
u'Organe %s'
%
json
[
'uid'
]
organe
=
self
.
get_cached
(
Organe
,
json
[
'uid'
])
organe
.
type
=
json
[
'codeType'
]
data
=
{
organe
.
libelle
=
json
[
'libelle'
]
'abbreviation'
:
json
[
'libelleAbrev'
],
organe
.
libelle_court
=
json
[
'libelleAbrege'
]
'date_debut'
:
None
,
organe
.
abbreviation
=
json
[
'libelleAbrev'
]
'date_fin'
:
None
,
'legislature'
:
None
,
'libelle'
:
json
[
'libelle'
],
'libelle_court'
:
json
[
'libelleAbrege'
],
'regime'
:
None
,
'type'
:
json
[
'codeType'
],
}
if
json
[
'viMoDe'
][
'dateDebut'
]:
if
json
[
'viMoDe'
][
'dateDebut'
]:
organe
.
date_debut
=
self
.
parse_date
(
json
[
'viMoDe'
][
'dateDebut'
])
data
[
'date_debut'
]
=
self
.
parse_date
(
json
[
'viMoDe'
][
'dateDebut'
])
else
:
organe
.
date_debut
=
None
if
json
[
'viMoDe'
][
'dateFin'
]:
if
json
[
'viMoDe'
][
'dateFin'
]:
organe
.
date_fin
=
self
.
parse_date
(
json
[
'viMoDe'
][
'dateFin'
])
data
[
'date_fin'
]
=
self
.
parse_date
(
json
[
'viMoDe'
][
'dateFin'
])
else
:
organe
.
date_fin
=
None
if
json
.
get
(
'regime'
,
None
):
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
):
if
json
.
get
(
'legislature'
,
None
):
organe
.
legislature
=
self
.
get_cached
(
Legislature
,
data
[
'legislature'
]
=
self
.
save
(
Legislature
,
int
(
json
[
'legislature'
]))
int
(
json
[
'legislature'
]))
if
organe
.
regime
:
if
data
[
'regime'
]:
organe
.
legislature
.
regime
=
organe
.
regime
data
[
'legislature'
].
regime
=
data
[
'regime'
]
organe
=
self
.
save
(
Organe
,
json
[
'uid'
],
data
)
def
run
(
app
,
force
=
False
,
file
=
None
):
def
run
(
app
,
force
=
False
,
file
=
None
):
...
...
parlapi/models.py
View file @
d71aedcf
...
@@ -41,6 +41,7 @@ class Regime(db.Model):
...
@@ -41,6 +41,7 @@ class Regime(db.Model):
__tablename__
=
'regimes'
__tablename__
=
'regimes'
query_class
=
SearchableQuery
query_class
=
SearchableQuery
_last_modified
=
db
.
Column
(
db
.
DateTime
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
nom
=
db
.
Column
(
db
.
Unicode
)
nom
=
db
.
Column
(
db
.
Unicode
)
...
@@ -54,6 +55,7 @@ class Regime(db.Model):
...
@@ -54,6 +55,7 @@ class Regime(db.Model):
class
Legislature
(
db
.
Model
):
class
Legislature
(
db
.
Model
):
__tablename__
=
'legislatures'
__tablename__
=
'legislatures'
_last_modified
=
db
.
Column
(
db
.
DateTime
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
date_debut
=
db
.
Column
(
db
.
Date
)
date_debut
=
db
.
Column
(
db
.
Date
)
date_fin
=
db
.
Column
(
db
.
Date
)
date_fin
=
db
.
Column
(
db
.
Date
)
...
@@ -78,6 +80,7 @@ class Organe(db.Model):
...
@@ -78,6 +80,7 @@ class Organe(db.Model):
__tablename__
=
'organes'
__tablename__
=
'organes'
query_class
=
SearchableQuery
query_class
=
SearchableQuery
_last_modified
=
db
.
Column
(
db
.
DateTime
)
id
=
db
.
Column
(
db
.
Unicode
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Unicode
,
primary_key
=
True
)
type
=
db
.
Column
(
db
.
Unicode
)
type
=
db
.
Column
(
db
.
Unicode
)
libelle
=
db
.
Column
(
db
.
Unicode
)
libelle
=
db
.
Column
(
db
.
Unicode
)
...
@@ -109,6 +112,7 @@ class Mandat(db.Model):
...
@@ -109,6 +112,7 @@ class Mandat(db.Model):
__tablename__
=
'mandats'
__tablename__
=
'mandats'
query_class
=
SearchableQuery
query_class
=
SearchableQuery
_last_modified
=
db
.
Column
(
db
.
DateTime
)
id
=
db
.
Column
(
db
.
Unicode
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Unicode
,
primary_key
=
True
)
date_debut
=
db
.
Column
(
db
.
Date
)
date_debut
=
db
.
Column
(
db
.
Date
)
...
@@ -146,6 +150,7 @@ class Acteur(db.Model):
...
@@ -146,6 +150,7 @@ class Acteur(db.Model):
__tablename__
=
'acteurs'
__tablename__
=
'acteurs'
query_class
=
SearchableQuery
query_class
=
SearchableQuery
_last_modified
=
db
.
Column
(
db
.
DateTime
)
id
=
db
.
Column
(
db
.
Unicode
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Unicode
,
primary_key
=
True
)
civilite
=
db
.
Column
(
db
.
Unicode
)
civilite
=
db
.
Column
(
db
.
Unicode
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment