Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
memopol
Commits
b97e979c
Commit
b97e979c
authored
Feb 13, 2016
by
Nicolas Joyard
Browse files
Add senate support to .contrib.francedata
parent
5a833c7b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
.travis.yml
View file @
b97e979c
...
...
@@ -13,7 +13,7 @@ script:
-
pep8 representatives/ --exclude migrations --ignore E128
-
flake8 representatives/ --exclude migrations --ignore E128
-
django-admin migrate
-
cat representatives/contrib/francedata/tests/
d
ep
utes
_input.json | francedata_import_representatives
-
cat representatives/contrib/francedata/tests/
r
ep
resentative
_input.json | francedata_import_representatives
-
cat representatives/contrib/parltrack/tests/representatives_fixture.json | parltrack_import_representatives
-
py.test
after_success
:
...
...
representatives/contrib/francedata/import_representatives.py
View file @
b97e979c
...
...
@@ -24,8 +24,12 @@ representative_pre_import = django.dispatch.Signal(
def
_get_rep_district_name
(
json
):
num
=
json
.
get
(
'num_circo'
)
nom
=
json
.
get
(
'nom_circo'
)
ordinal
=
u
'ère'
if
num
==
1
else
u
'ème'
return
'%s (%d%s circonscription)'
%
(
nom
,
num
,
ordinal
)
if
num
==
'nd'
:
return
nom
else
:
ordinal
=
u
'ère'
if
num
==
1
else
u
'ème'
return
'%s (%d%s circonscription)'
%
(
nom
,
num
,
ordinal
)
def
_get_rep_parl_groups
(
json
):
...
...
@@ -83,19 +87,69 @@ FranceDataVariants = {
"chamber"
:
True
,
"abbr"
:
"%(groupe_sigle)s"
,
"name_path"
:
"groupe/organisme"
,
"role_path"
:
"groupe/fonction"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"department"
,
"chamber"
:
True
,
"abbr"
:
"%(num_deptmt)s"
,
"name"
:
"%(nom_circo)s"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"district"
,
"abbr"
:
"%(num_deptmt)s-%(num_circo)s"
,
"name_fn"
:
_get_rep_district_name
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"parl-group"
,
"chamber"
:
True
,
"from"
:
_get_rep_parl_groups
,
"abbr"
:
"%(name)s"
,
"name"
:
"%(name)s"
,
"role"
:
"%(role)s"
,
"start"
:
"%(start)s"
},
{
"kind"
:
"comittee"
,
"chamber"
:
True
,
"abbr"
:
"%(num_deptmt)s-%(num_circo)d"
,
"from"
:
_get_rep_comittees
,
"abbr"
:
"%(name)s"
,
"name"
:
"%(name)s"
,
"role"
:
"%(role)s"
,
"start"
:
"%(start)s"
}
]
},
"SEN"
:
{
"chamber"
:
u
"Sénat"
,
"remote_id_field"
:
"id_institution"
,
"mail_domain"
:
"@senat.fr"
,
"off_city"
:
"Paris"
,
"off_street"
:
u
"Rue de Vaugirard"
,
"off_number"
:
"15"
,
"off_code"
:
"75291"
,
"off_name"
:
u
"Palais du Luxembourg"
,
"mandates"
:
[
{
"kind"
:
"group"
,
"chamber"
:
True
,
"abbr"
:
"%(groupe_sigle)s"
,
"name_path"
:
"groupe/organisme"
,
"role_path"
:
"groupe/fonction"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"department"
,
"abbr"
:
"%(num_deptmt)s"
,
"name"
:
"%(nom_circo)s"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"district"
,
"abbr"
:
"%(num_deptmt)s-%(num_circo)s"
,
"name_fn"
:
_get_rep_district_name
,
"start"
:
"%(mandat_debut)s"
},
...
...
@@ -187,7 +241,7 @@ class GenericImporter(object):
class
FranceDataImporter
(
GenericImporter
):
url
=
'http://francedata.future/data/
deput
es.json'
url
=
'http://francedata.future/data/
parlementair
es.json'
def
parse_date
(
self
,
date
):
return
_parse_date
(
date
)
...
...
@@ -211,6 +265,9 @@ class FranceDataImporter(GenericImporter):
'''
remote_id
=
rep_json
[
self
.
variant
[
'remote_id_field'
]]
if
rep_json
[
'num_circo'
]
==
'non disponible'
:
rep_json
[
'num_circo'
]
=
'nd'
if
not
remote_id
:
logger
.
warning
(
'Skipping MEP without UID %s %s'
,
rep_json
[
'nom'
],
...
...
@@ -400,9 +457,15 @@ def main(stream=None):
if
not
apps
.
ready
:
django
.
setup
()
importer
=
FranceDataImporter
(
'AN'
)
GenericImporter
.
pre_import
(
importer
)
an_importer
=
FranceDataImporter
(
'AN'
)
GenericImporter
.
pre_import
(
an_importer
)
sen_importer
=
FranceDataImporter
(
'SEN'
)
GenericImporter
.
pre_import
(
sen_importer
)
for
data
in
ijson
.
items
(
stream
or
sys
.
stdin
,
''
):
for
rep
in
data
:
importer
.
manage_rep
(
rep
)
if
rep
[
'chambre'
]
==
'AN'
:
an_importer
.
manage_rep
(
rep
)
elif
rep
[
'chambre'
]
==
'SEN'
:
sen_importer
.
manage_rep
(
rep
)
representatives/contrib/francedata/tests/
d
ep
ut
es_expected.json
→
representatives/contrib/francedata/tests/
r
ep
resentativ
es_expected.json
View file @
b97e979c
This diff is collapsed.
Click to expand it.
representatives/contrib/francedata/tests/
d
ep
ut
es_input.json
→
representatives/contrib/francedata/tests/
r
ep
resentativ
es_input.json
View file @
b97e979c
...
...
@@ -4,6 +4,7 @@
"profession"
:
"Avocat, administrateur territorial"
,
"url_nosdeputes_api"
:
"https://www.nosdeputes.fr/bernard-roman/json"
,
"nb_mandats"
:
2
,
"chambre"
:
"AN"
,
"id"
:
153
,
"groupes_parlementaires"
:
[
{
...
...
@@ -182,224 +183,101 @@
]
},
{
"twitter"
:
""
,
"profession"
:
"Pharmacien"
,
"url_nosdeputes_api"
:
"http://www.nosdeputes.fr/jean-pierre-barbier/json"
,
"nb_mandats"
:
2
,
"id"
:
413
,
"mandat_debut"
:
"2004-09-26"
,
"twitter"
:
"dassouline"
,
"profession"
:
"Professeur d'histoire-géographie"
,
"url_nossenateurs_api"
:
"http://www.nossenateurs.fr/david-assouline/json"
,
"chambre"
:
"SEN"
,
"nb_mandats"
:
3
,
"id"
:
44
,
"groupes_parlementaires"
:
[
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études Économie verte et économie circulaire"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études aménagement du territoire"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études politique de l'eau"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études coordination des droits européens"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études automobile"
,
"fonction"
:
"vice-président"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études prévention et lutte contre la toxicomanie"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'amitié france-république d'autriche"
,
"fonction"
:
"vice-président"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études chrétiens d'orient"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études granit, pierres naturelles, carrières et matériaux de construction"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études Élevage"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études sectes"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études famille et adoption"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études enseignement privé sous contrat et hors contrat"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études pme"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études république et religions"
,
"organisme"
:
"Groupe France-Japon"
,
"fonction"
:
"président"
}
}
,
{
"
responsabilite"
:
{
"organisme"
:
"Groupe d'études industrie chimiqu
e"
,
"fonction"
:
"membre"
}
},
}
],
"
sexe"
:
"H"
,
"lieu_naissance"
:
"non disponibl
e"
,
"anciens_autres_mandats"
:
[],
"url_nossenateurs"
:
"http://www.nossenateurs.fr/david-assouline"
,
"emails"
:
[
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études antisémitisme"
,
"fonction"
:
"membre"
}
},
"email"
:
"d.assouline@senat.fr"
}
],
"responsabilites_extra_parlementaires"
:
[
{
"responsabilite"
:
{
"organisme"
:
"
Groupe d'études alimentation et santé
"
,
"organisme"
:
"
Centre national du cinéma et de l'image animée
"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études politiques de la ruralité"
,
"fonction"
:
"secrétaire"
}
},
{
"responsabilite"
:
{
"organisme"
:
"Groupe d'études médicaments et produits de santé"
,
"organisme"
:
"Commission de modernisation de la diffusion audiovisuelle"
,
"fonction"
:
"membre"
}
},
{
"responsabilite"
:
{
"organisme"
:
"
Groupe d'études développ
ement de la
méthanisation
"
,
"organisme"
:
"
Section française de l'Assemblée parl
ement
aire
de la
francophonie (A.P.F)
"
,
"fonction"
:
"membre"
}
}
],
"sexe"
:
"H"
,
"lieu_naissance"
:
"Bron (Rhône)"
,
"anciens_autres_mandats"
:
[],
"mandat_debut"
:
"2012-06-20"
,
"emails"
:
[
"anciens_mandats"
:
[
{
"
e
ma
il"
:
"jpbarbier.depute@orange.fr
"
"ma
ndat"
:
"25/09/2011 / /
"
},
{
"email"
:
"jpbarbier@assemblee-nationale.fr"
}
],
"responsabilites_extra_parlementaires"
:
[],
"anciens_mandats"
:
[
{
"mandat"
:
"20/06/2012 / / "
"mandat"
:
"26/09/2004 / 25/09/2011 / "
}
],
"url_institution"
:
"http://www.senat.fr/senateur/assouline_david04059m.html"
,
"parti_ratt_financier"
:
"Parti socialiste"
,
"groupe"
:
{
"organisme"
:
"
Les
républicain
s
"
,
"organisme"
:
"
Socialiste et
républicain"
,
"fonction"
:
"membre"
},
"nom"
:
"
Jean-Pierre Barbier
"
,
"nom"
:
"
David Assouline
"
,
"sites_web"
:
[
{
"site"
:
"http://www.jeanpierrebarbier.fr"
}
],
"groupe_sigle"
:
"LES-REP"
,
"nom_circo"
:
"Isère"
,
"parti_ratt_financier"
:
"Les Républicains"
,
"place_en_hemicycle"
:
"64"
,
"autres_mandats"
:
[
"site"
:
"http://www.david-assouline.net"
},
{
"mandat"
:
"Isère / Conseil départemental / président"
}
],
"url_nosdeputes"
:
"http://www.nosdeputes.fr/jean-pierre-barbier"
,
"url_an"
:
"http://www2.assemblee-nationale.fr/deputes/fiche/OMC_PA606888"
,
"adresses"
:
[
"site"
:
"https://twitter.com/dassouline"
},
{
"
adresse"
:
"Assemblée nationale, 126 Rue de l'Université 75355 PARIS 07 SP
"
"
site"
:
"https://www.facebook.com/DavAssouline
"
},
{
"geo"
:
{
"geometry"
:
{
"type"
:
"Point"
,
"coordinates"
:
[
5.26302
,
45.392192
]
},
"type"
:
"Feature"
,
"properties"
:
{
"city"
:
"La Côte-Saint-André"
,
"citycode"
:
"38130"
,
"name"
:
"6 Allée Jean Jaurès"
,
"type"
:
"housenumber"
,
"label"
:
"6 Allée Jean Jaurès 38260 La Côte-Saint-André"
,
"street"
:
"Allée Jean Jaurès"
,
"postcode"
:
"38260"
,
"context"
:
"38, Isère, Rhône-Alpes"
,
"score"
:
0.3896703153988868
,
"housenumber"
:
"6"
,
"id"
:
"ADRNIVX_0000000326062287"
}
},
"tel"
:
"04 74 59 76 76"
,
"fax"
:
"04 74 59 76 70"
,
"adresse"
:
"6 Avenue Jean jaurès 38260 La Côte Saint-André Télécopie : 04 74 59 76 70 Téléphone : 04 74 59 76 76"
"site"
:
"http://david-assouline.net"
}
],
"groupe_sigle"
:
"SOC"
,
"nom_circo"
:
"Paris"
,
"id_institution"
:
"assouline_david04059m"
,
"place_en_hemicycle"
:
"114"
,
"autres_mandats"
:
[
{
"mandat"
:
"Paris (20ème arrondissement) / conseiller"
}
],
"
date_naissance"
:
"1960-11-11"
,
"
slug"
:
"jean-pierre-barbier
"
,
"
id_an"
:
"606888
"
,
"photo_url"
:
"http://www.nos
deputes.fr/depute/photo/jean-pierre-barbier
"
,
"prenom"
:
"
Jean-Pierre
"
,
"num_deptmt"
:
"
38
"
,
"nom_de_famille"
:
"
Barbier
"
,
"num_circo"
:
7
,
"
adresses"
:
[]
,
"
date_naissance"
:
"1959-06-16
"
,
"
slug"
:
"david-assouline
"
,
"photo_url"
:
"http://www.nos
senateurs.fr/senateur/photo/david-assouline
"
,
"prenom"
:
"
David
"
,
"num_deptmt"
:
"
75
"
,
"nom_de_famille"
:
"
Assouline
"
,
"num_circo"
:
"non disponible"
,
"responsabilites"
:
[
{
"responsabilite"
:
{
"organisme"
:
"Commission de
s affaires sociales
"
,
"fonction"
:
"
membre
"
"organisme"
:
"Commission de
la culture, de l'éducation et de la communication
"
,
"fonction"
:
"
vice-président
"
}
}
]
...
...
representatives/contrib/francedata/tests/test_francedata_import_representatives.py
View file @
b97e979c
...
...
@@ -10,9 +10,9 @@ from representatives.contrib.francedata import import_representatives
@
pytest
.
mark
.
django_db
def
test_francedata_import_representatives
():
inputjson
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
d
ep
ut
es_input.json'
)
'
r
ep
resentativ
es_input.json'
)
expected
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
d
ep
ut
es_expected.json'
)
'
r
ep
resentativ
es_expected.json'
)
# Disable django auto fields
exclude
=
(
'id'
,
'_state'
,
'created'
,
'updated'
,
'fingerprint'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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