Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
regardscitoyens
/
parlapi
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
Merge Requests
1
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3ca5e5d4
authored
Apr 04, 2018
by
Nicolas Joyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move to python3 and fix flake8 errors
parent
d40a316d
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
182 additions
and
192 deletions
README.md
flake8.conf
parlapi/jobs/an/amendements.py
parlapi/jobs/an/amo.py
parlapi/jobs/an/dossiers.py
parlapi/jobs/an/reunions.py
parlapi/jobs/an/scrutins.py
parlapi/jobs/base.py
parlapi/models/__init__.py
parlapi/models/an.py
parlapi/models/parlapi.py
parlapi/rest/endpoint.py
parlapi/rest/schema.py
parlapi/rest/setup.py
parlapi/routes.py
parlapi/setup_app.py
setup.py
README.md
View file @
3ca5e5d4
...
@@ -16,7 +16,7 @@ n'est ajoutée au modèle.
...
@@ -16,7 +16,7 @@ n'est ajoutée au modèle.
### Prérequis
### Prérequis
-
Python
2.7
-
Python
3.6
-
PostgreSQL 9.2+
-
PostgreSQL 9.2+
-
pip
-
pip
-
virtualenv
-
virtualenv
...
@@ -49,19 +49,6 @@ $ parlapi runserver
...
@@ -49,19 +49,6 @@ $ parlapi runserver
$
parlapi db upgrade
$
parlapi db upgrade
```
```
### Déploiement Openshift
```
bash
$
export
APP
=
parlapi
$
rhc app-create
$APP
python-2.7 postgresql-9.2
$
rhc env
set
-a
$APP
OPENSHIFT_PYTHON_WSGI_APPLICATION
=
wsgi.py
$
rhc env
set
-a
$APP
PARLAPI_CONFIG
=
parlapi.config.OpenshiftConfig
$
rhc app show
-a
$APP
|
grep
Git
Git URL: ssh://xxx@parlapi-xxx.rhcloud.com/~/git/parlapi.git/
$
git remote add openshift ssh://xxx@parlapi-xxx.rhcloud.com/~/git/parlapi.git/
$
git push
--force
openshift openshift:master
```
### Déploiement Apache2/mod_wsgi
### Déploiement Apache2/mod_wsgi
Voir le rôle
`parlapi`
dans le
[
playbook citoyen
][
gh-playbook
]
Voir le rôle
`parlapi`
dans le
[
playbook citoyen
][
gh-playbook
]
...
...
flake8.conf
0 → 100644
View file @
3ca5e5d4
[
flake8
]
exclude
=.
git
,
__
pycache__
,
migrations
parlapi/jobs/an/amendements.py
View file @
3ca5e5d4
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
from
..base
import
BaseANJob
from
..base
import
BaseANJob
from
..utils
import
ijson_items
from
..utils
import
ijson_items
from
...models.an
import
(
Amendement
,
ActeurAmendement
,
Document
,
Legislature
,
from
...models.an
import
(
Amendement
,
ActeurAmendement
,
Document
,
Legislature
,
Organe
)
Organe
)
class
ImportAmendementsJob
(
BaseANJob
):
class
ImportAmendementsJob
(
BaseANJob
):
...
@@ -24,7 +24,7 @@ class ImportAmendementsJob(BaseANJob):
...
@@ -24,7 +24,7 @@ class ImportAmendementsJob(BaseANJob):
self
.
save_texte
(
obj
)
self
.
save_texte
(
obj
)
def
save_texte
(
self
,
json
):
def
save_texte
(
self
,
json
):
self
.
current
=
u
'Texte
%
s'
%
json
[
'refTexteLegislatif'
]
self
.
current
=
'Texte
%
s'
%
json
[
'refTexteLegislatif'
]
document
=
self
.
save
(
Document
,
json
[
'refTexteLegislatif'
])
document
=
self
.
save
(
Document
,
json
[
'refTexteLegislatif'
])
...
@@ -36,7 +36,7 @@ class ImportAmendementsJob(BaseANJob):
...
@@ -36,7 +36,7 @@ class ImportAmendementsJob(BaseANJob):
self
.
save_amendement
(
am
,
document
)
self
.
save_amendement
(
am
,
document
)
def
save_amendement
(
self
,
json
,
document
):
def
save_amendement
(
self
,
json
,
document
):
self
.
current
=
u
'Amendement
%
s'
%
json
[
'uid'
]
self
.
current
=
'Amendement
%
s'
%
json
[
'uid'
]
id
=
json
[
'identifiant'
]
id
=
json
[
'identifiant'
]
fr
=
json
[
'pointeurFragmentTexte'
]
fr
=
json
[
'pointeurFragmentTexte'
]
...
@@ -58,8 +58,10 @@ class ImportAmendementsJob(BaseANJob):
...
@@ -58,8 +58,10 @@ class ImportAmendementsJob(BaseANJob):
'date_sort'
:
None
,
'date_sort'
:
None
,
'division_alinea'
:
None
,
'division_alinea'
:
None
,
'division_alinea_position'
:
None
,
'division_alinea_position'
:
None
,
'division_article_additionnel'
:
dv
.
get
(
'articleAdditionnel'
,
'0'
)
!=
'0'
,
'division_article_additionnel'
:
'division_chapitre_additionnel'
:
dv
.
get
(
'chapitreAdditionnel'
,
'0'
)
!=
'0'
,
dv
.
get
(
'articleAdditionnel'
,
'0'
)
!=
'0'
,
'division_chapitre_additionnel'
:
dv
.
get
(
'chapitreAdditionnel'
,
'0'
)
!=
'0'
,
'division_position'
:
dv
[
'avant_A_Apres'
],
'division_position'
:
dv
[
'avant_A_Apres'
],
'division_texte'
:
dv
[
'titre'
],
'division_texte'
:
dv
[
'titre'
],
'document'
:
document
,
'document'
:
document
,
...
@@ -94,7 +96,7 @@ class ImportAmendementsJob(BaseANJob):
...
@@ -94,7 +96,7 @@ class ImportAmendementsJob(BaseANJob):
auteur_ref
=
None
auteur_ref
=
None
if
'acteurRef'
in
auteur
and
auteur
[
'acteurRef'
]:
if
'acteurRef'
in
auteur
and
auteur
[
'acteurRef'
]:
auteur_ref
=
auteur
[
'acteurRef'
]
auteur_ref
=
auteur
[
'acteurRef'
]
aa
=
ActeurAmendement
(
relation
=
u
'auteur'
)
aa
=
ActeurAmendement
(
relation
=
'auteur'
)
aa
.
acteur_id
=
auteur_ref
aa
.
acteur_id
=
auteur_ref
signataires
.
append
(
aa
)
signataires
.
append
(
aa
)
...
@@ -105,13 +107,13 @@ class ImportAmendementsJob(BaseANJob):
...
@@ -105,13 +107,13 @@ class ImportAmendementsJob(BaseANJob):
else
:
else
:
cosignataires
=
cosignataires
[
'acteurRef'
]
cosignataires
=
cosignataires
[
'acteurRef'
]
if
isinstance
(
cosignataires
,
basestring
):
if
isinstance
(
cosignataires
,
str
):
cosignataires
=
[
cosignataires
]
cosignataires
=
[
cosignataires
]
for
cosignataire
in
cosignataires
:
for
cosignataire
in
cosignataires
:
if
auteur_ref
and
cosignataire
==
auteur_ref
:
if
auteur_ref
and
cosignataire
==
auteur_ref
:
continue
continue
acs
=
ActeurAmendement
(
relation
=
u
'cosignataire'
)
acs
=
ActeurAmendement
(
relation
=
'cosignataire'
)
acs
.
acteur_id
=
cosignataire
acs
.
acteur_id
=
cosignataire
signataires
.
append
(
acs
)
signataires
.
append
(
acs
)
...
@@ -127,12 +129,12 @@ class ImportAmendementsJob(BaseANJob):
...
@@ -127,12 +129,12 @@ class ImportAmendementsJob(BaseANJob):
data
[
'division_alinea'
]
=
int
(
al
[
'numero'
])
data
[
'division_alinea'
]
=
int
(
al
[
'numero'
])
data
[
'division_alinea_position'
]
=
al
[
'avant_A_Apres'
]
data
[
'division_alinea_position'
]
=
al
[
'avant_A_Apres'
]
am
=
self
.
save
(
Amendement
,
json
[
'uid'
],
data
)
self
.
save
(
Amendement
,
json
[
'uid'
],
data
)
def
run
(
app
,
force
=
False
,
file
=
None
):
def
run
(
app
,
force
=
False
,
file
=
None
):
ImportAmendementsJob
(
ImportAmendementsJob
(
app
,
app
,
u
'AN: amendements'
,
'AN: amendements'
,
'/travaux-parlementaires/amendements'
'/travaux-parlementaires/amendements'
)
.
run
(
force
,
file
)
)
.
run
(
force
,
file
)
parlapi/jobs/an/amo.py
View file @
3ca5e5d4
...
@@ -26,7 +26,7 @@ class ImportAMOJob(BaseANJob):
...
@@ -26,7 +26,7 @@ class ImportAMOJob(BaseANJob):
self
.
save_organe
(
obj
)
self
.
save_organe
(
obj
)
def
save_acteur
(
self
,
json
):
def
save_acteur
(
self
,
json
):
self
.
current
=
u
'Acteur
%
s'
%
json
[
'uid'
][
'#text'
]
self
.
current
=
'Acteur
%
s'
%
json
[
'uid'
][
'#text'
]
ec
=
json
[
'etatCivil'
]
ec
=
json
[
'etatCivil'
]
id
=
ec
[
'ident'
]
id
=
ec
[
'ident'
]
...
@@ -62,9 +62,9 @@ class ImportAMOJob(BaseANJob):
...
@@ -62,9 +62,9 @@ class ImportAMOJob(BaseANJob):
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
=
'Mandat
%
s'
%
json
[
'uid'
]
if
isinstance
(
json
[
'organes'
][
'organeRef'
],
basestring
):
if
isinstance
(
json
[
'organes'
][
'organeRef'
],
str
):
organe_refs
=
[
json
[
'organes'
][
'organeRef'
]]
organe_refs
=
[
json
[
'organes'
][
'organeRef'
]]
else
:
else
:
organe_refs
=
json
[
'organes'
][
'organeRef'
]
organe_refs
=
json
[
'organes'
][
'organeRef'
]
...
@@ -115,10 +115,10 @@ class ImportAMOJob(BaseANJob):
...
@@ -115,10 +115,10 @@ class ImportAMOJob(BaseANJob):
if
li
[
'numCirco'
]:
if
li
[
'numCirco'
]:
data
[
'election_circo'
]
=
int
(
li
[
'numCirco'
])
data
[
'election_circo'
]
=
int
(
li
[
'numCirco'
])
mandat
=
self
.
save
(
Mandat
,
json
[
'uid'
],
data
)
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
=
'Organe
%
s'
%
json
[
'uid'
]
data
=
{
data
=
{
'abbreviation'
:
json
[
'libelleAbrev'
],
'abbreviation'
:
json
[
'libelleAbrev'
],
...
@@ -142,18 +142,18 @@ class ImportAMOJob(BaseANJob):
...
@@ -142,18 +142,18 @@ class ImportAMOJob(BaseANJob):
if
json
.
get
(
'legislature'
,
None
):
if
json
.
get
(
'legislature'
,
None
):
data
[
'legislature'
]
=
self
.
save
(
Legislature
,
data
[
'legislature'
]
=
self
.
save
(
Legislature
,
int
(
json
[
'legislature'
]))
int
(
json
[
'legislature'
]))
if
data
[
'regime'
]:
if
data
[
'regime'
]:
data
[
'legislature'
]
.
regime
=
data
[
'regime'
]
data
[
'legislature'
]
.
regime
=
data
[
'regime'
]
organe
=
self
.
save
(
Organe
,
json
[
'uid'
],
data
)
self
.
save
(
Organe
,
json
[
'uid'
],
data
)
def
run
(
app
,
force
=
False
,
file
=
None
):
def
run
(
app
,
force
=
False
,
file
=
None
):
if
file
:
if
file
:
ImportAMOJob
(
app
,
u
'AN: députés (historique)'
,
''
)
.
run
(
force
,
file
)
ImportAMOJob
(
app
,
'AN: députés (historique)'
,
''
)
.
run
(
force
,
file
)
else
:
else
:
ImportAMOJob
(
app
,
u
'AN: députés-sénateurs-ministres'
,
ImportAMOJob
(
app
,
'AN: députés-sénateurs-ministres'
,
'/acteurs/deputes-senateurs-ministres'
)
.
run
(
force
)
'/acteurs/deputes-senateurs-ministres'
)
.
run
(
force
)
ImportAMOJob
(
app
,
u
'AN: députés (historique)'
,
ImportAMOJob
(
app
,
'AN: députés (historique)'
,
'/acteurs/historique-des-deputes'
)
.
run
(
force
)
'/acteurs/historique-des-deputes'
)
.
run
(
force
)
parlapi/jobs/an/dossiers.py
View file @
3ca5e5d4
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
from
..base
import
BaseANJob
from
..base
import
BaseANJob
from
..utils
import
ijson_items
from
..utils
import
ijson_items
from
...models.an
import
(
Organe
,
Legislature
,
Acteur
,
Document
,
Theme
,
Mandat
,
from
...models.an
import
(
Organe
,
Legislature
,
Acteur
,
Document
,
Theme
,
Mandat
,
ActeurDocument
,
OrganeDocument
,
Dossier
,
Acte
,
ActeurDocument
,
OrganeDocument
,
Dossier
,
Acte
,
OrganeDossier
,
ActeurDossier
)
OrganeDossier
,
ActeurDossier
)
class
ImportDossiersJob
(
BaseANJob
):
class
ImportDossiersJob
(
BaseANJob
):
...
@@ -30,14 +30,14 @@ class ImportDossiersJob(BaseANJob):
...
@@ -30,14 +30,14 @@ class ImportDossiersJob(BaseANJob):
def
save_document
(
self
,
json
,
chaine
=
[]):
def
save_document
(
self
,
json
,
chaine
=
[]):
if
json
[
'uid'
]
in
chaine
:
if
json
[
'uid'
]
in
chaine
:
self
.
warn
(
self
.
warn
(
u
'Dépendance circulaire sur documents:
%
s >
%
s'
%
'Dépendance circulaire sur documents:
%
s >
%
s'
%
(
' > '
.
join
(
chaine
),
json
[
'uid'
])
(
' > '
.
join
(
chaine
),
json
[
'uid'
])
)
)
return
None
return
None
chaine
.
append
(
json
[
'uid'
])
chaine
.
append
(
json
[
'uid'
])
self
.
current
=
u
'Document
%
s'
%
json
[
'uid'
]
self
.
current
=
'Document
%
s'
%
json
[
'uid'
]
chrono
=
json
[
'cycleDeVie'
][
'chrono'
]
chrono
=
json
[
'cycleDeVie'
][
'chrono'
]
klass
=
json
[
'classification'
]
klass
=
json
[
'classification'
]
...
@@ -48,7 +48,8 @@ class ImportDossiersJob(BaseANJob):
...
@@ -48,7 +48,8 @@ class ImportDossiersJob(BaseANJob):
'date_creation'
:
self
.
parse_date
(
chrono
[
'dateCreation'
]),
'date_creation'
:
self
.
parse_date
(
chrono
[
'dateCreation'
]),
'date_depot'
:
self
.
parse_date
(
chrono
[
'dateDepot'
]),
'date_depot'
:
self
.
parse_date
(
chrono
[
'dateDepot'
]),
'date_publication'
:
self
.
parse_date
(
chrono
[
'datePublication'
]),
'date_publication'
:
self
.
parse_date
(
chrono
[
'datePublication'
]),
'date_publication_web'
:
self
.
parse_date
(
chrono
[
'datePublicationWeb'
]),
'date_publication_web'
:
self
.
parse_date
(
chrono
[
'datePublicationWeb'
]),
'denomination_structurelle'
:
json
[
'denominationStructurelle'
],
'denomination_structurelle'
:
json
[
'denominationStructurelle'
],
'divisions'
:
[],
'divisions'
:
[],
'dossier'
:
None
,
'dossier'
:
None
,
...
@@ -72,13 +73,15 @@ class ImportDossiersJob(BaseANJob):
...
@@ -72,13 +73,15 @@ class ImportDossiersJob(BaseANJob):
data
[
'soustype_libelle'
]
=
klass
[
'sousType'
]
.
get
(
'libelle'
,
None
)
data
[
'soustype_libelle'
]
=
klass
[
'sousType'
]
.
get
(
'libelle'
,
None
)
if
json
.
get
(
'legislature'
,
None
):
if
json
.
get
(
'legislature'
,
None
):
data
[
'legislature'
]
=
self
.
save
(
Legislature
,
int
(
json
[
'legislature'
]))
data
[
'legislature'
]
=
self
.
save
(
Legislature
,
int
(
json
[
'legislature'
]))
if
'dossierRef'
in
json
:
if
'dossierRef'
in
json
:
data
[
'dossier'
]
=
self
.
save
(
Dossier
,
json
[
'dossierRef'
])
data
[
'dossier'
]
=
self
.
save
(
Dossier
,
json
[
'dossierRef'
])
if
json
.
get
(
'indexation'
,
None
):
if
json
.
get
(
'indexation'
,
None
):
data
[
'themes'
]
=
[
self
.
save
(
Theme
,
json
[
'indexation'
][
'themes'
][
'theme'
][
'libelleTheme'
])]
libelle
=
json
[
'indexation'
][
'themes'
][
'theme'
][
'libelleTheme'
]
data
[
'themes'
]
=
[
self
.
save
(
Theme
,
libelle
)]
if
json
.
get
(
'divisions'
,
None
):
if
json
.
get
(
'divisions'
,
None
):
divs
=
json
[
'divisions'
][
'division'
]
divs
=
json
[
'divisions'
][
'division'
]
...
@@ -99,15 +102,15 @@ class ImportDossiersJob(BaseANJob):
...
@@ -99,15 +102,15 @@ class ImportDossiersJob(BaseANJob):
for
auteur
in
auteurs
:
for
auteur
in
auteurs
:
if
'acteur'
in
auteur
:
if
'acteur'
in
auteur
:
qual
=
auteur
[
'acteur'
]
.
get
(
'qualite'
,
None
)
qual
=
auteur
[
'acteur'
]
.
get
(
'qualite'
,
None
)
ad
=
ActeurDocument
(
relation
=
u
'auteur'
,
qualite
=
qual
)
ad
=
ActeurDocument
(
relation
=
'auteur'
,
qualite
=
qual
)
ad
.
acteur
=
self
.
save
(
Acteur
,
auteur
[
'acteur'
][
'acteurRef'
])
ad
.
acteur
=
self
.
save
(
Acteur
,
auteur
[
'acteur'
][
'acteurRef'
])
acteurs
.
append
(
ad
)
acteurs
.
append
(
ad
)
elif
'organe'
in
auteur
:
elif
'organe'
in
auteur
:
od
=
OrganeDocument
(
relation
=
u
'auteur'
)
od
=
OrganeDocument
(
relation
=
'auteur'
)
od
.
organe
=
self
.
save
(
Organe
,
auteur
[
'organe'
][
'organeRef'
])
od
.
organe
=
self
.
save
(
Organe
,
auteur
[
'organe'
][
'organeRef'
])
organes
.
append
(
od
)
organes
.
append
(
od
)
else
:
else
:
self
.
warn
(
u
'Ignoré type auteur inconnu dans
%
s'
%
self
.
current
)
self
.
warn
(
'Ignoré type auteur inconnu dans
%
s'
%
self
.
current
)
if
json
.
get
(
'coSignataires'
,
None
):
if
json
.
get
(
'coSignataires'
,
None
):
cosign
=
json
[
'coSignataires'
][
'coSignataire'
]
cosign
=
json
[
'coSignataires'
][
'coSignataire'
]
...
@@ -122,17 +125,18 @@ class ImportDossiersJob(BaseANJob):
...
@@ -122,17 +125,18 @@ class ImportDossiersJob(BaseANJob):
dr
=
None
dr
=
None
if
'acteur'
in
auteur
:
if
'acteur'
in
auteur
:
ad
=
ActeurDocument
(
relation
=
u
'cosignataire'
,
ad
=
ActeurDocument
(
relation
=
'cosignataire'
,
date_cosignature
=
dc
,
date_cosignature
=
dc
,
date_retrait_cosignature
=
dr
)
date_retrait_cosignature
=
dr
)
ad
.
acteur
=
self
.
save
(
Acteur
,
ad
.
acteur
=
self
.
save
(
Acteur
,
auteur
[
'acteur'
][
'acteurRef'
])
auteur
[
'acteur'
][
'acteurRef'
])
acteurs
.
append
(
ad
)
acteurs
.
append
(
ad
)
elif
'organe'
in
auteur
:
elif
'organe'
in
auteur
:
od
=
OrganeDocument
(
relation
=
u
'cosignataire'
,
od
=
OrganeDocument
(
relation
=
'cosignataire'
,
date_cosignature
=
dc
,
date_cosignature
=
dc
,
date_retrait_cosignature
=
dr
)
date_retrait_cosignature
=
dr
)
od
.
organe
=
self
.
save
(
Organe
,
auteur
[
'organe'
][
'organeRef'
])
od
.
organe
=
self
.
save
(
Organe
,
auteur
[
'organe'
][
'organeRef'
])
organes
.
append
(
od
)
organes
.
append
(
od
)
data
[
'acteurs'
]
=
acteurs
data
[
'acteurs'
]
=
acteurs
...
@@ -144,7 +148,7 @@ class ImportDossiersJob(BaseANJob):
...
@@ -144,7 +148,7 @@ class ImportDossiersJob(BaseANJob):
return
document
return
document
def
save_dossier
(
self
,
json
):
def
save_dossier
(
self
,
json
):
self
.
current
=
u
'Dossier
%
s'
%
json
[
'uid'
]
self
.
current
=
'Dossier
%
s'
%
json
[
'uid'
]
td
=
json
[
'titreDossier'
]
td
=
json
[
'titreDossier'
]
pp
=
json
[
'procedureParlementaire'
]
pp
=
json
[
'procedureParlementaire'
]
...
@@ -177,7 +181,7 @@ class ImportDossiersJob(BaseANJob):
...
@@ -177,7 +181,7 @@ class ImportDossiersJob(BaseANJob):
if
isinstance
(
acteurs
,
dict
):
if
isinstance
(
acteurs
,
dict
):
acteurs
=
[
acteurs
]
acteurs
=
[
acteurs
]
for
acteur
in
acteurs
:
for
acteur
in
acteurs
:
ad
=
ActeurDossier
(
relation
=
u
'initiateur'
)
ad
=
ActeurDossier
(
relation
=
'initiateur'
)
ad
.
acteur
=
self
.
save
(
Acteur
,
acteur
[
'acteurRef'
])
ad
.
acteur
=
self
.
save
(
Acteur
,
acteur
[
'acteurRef'
])
ad
.
mandat
=
self
.
save
(
Mandat
,
acteur
[
'mandatRef'
])
ad
.
mandat
=
self
.
save
(
Mandat
,
acteur
[
'mandatRef'
])
acteursdossier
.
append
(
ad
)
acteursdossier
.
append
(
ad
)
...
@@ -186,7 +190,7 @@ class ImportDossiersJob(BaseANJob):
...
@@ -186,7 +190,7 @@ class ImportDossiersJob(BaseANJob):
if
isinstance
(
organes
,
dict
):
if
isinstance
(
organes
,
dict
):
organes
=
[
organes
]
organes
=
[
organes
]
for
organe
in
organes
:
for
organe
in
organes
:
od
=
OrganeDossier
(
relation
=
u
'initiateur'
)
od
=
OrganeDossier
(
relation
=
'initiateur'
)
od
.
organe
=
self
.
save
(
Organe
,
organe
[
'organeRef'
][
'uid'
])
od
.
organe
=
self
.
save
(
Organe
,
organe
[
'organeRef'
][
'uid'
])
organesdossier
.
append
(
od
)
organesdossier
.
append
(
od
)
...
@@ -197,7 +201,7 @@ class ImportDossiersJob(BaseANJob):
...
@@ -197,7 +201,7 @@ class ImportDossiersJob(BaseANJob):
return
dossier
return
dossier
def
save_acte
(
self
,
json
):
def
save_acte
(
self
,
json
):
self
.
current
=
u
'Acte
%
s'
%
json
[
'uid'
]
self
.
current
=
'Acte
%
s'
%
json
[
'uid'
]
data
=
{
data
=
{
'code'
:
json
[
'codeActe'
],
'code'
:
json
[
'codeActe'
],
...
@@ -208,7 +212,6 @@ class ImportDossiersJob(BaseANJob):
...
@@ -208,7 +212,6 @@ class ImportDossiersJob(BaseANJob):
'document'
:
None
'document'
:
None
}
}
if
json
.
get
(
'date'
,
None
):
if
json
.
get
(
'date'
,
None
):
data
[
'date'
]
=
self
.
parse_date
(
json
[
'date'
])
data
[
'date'
]
=
self
.
parse_date
(
json
[
'date'
])
elif
json
.
get
(
'dateActe'
,
None
):
elif
json
.
get
(
'dateActe'
,
None
):
...
@@ -234,6 +237,6 @@ class ImportDossiersJob(BaseANJob):
...
@@ -234,6 +237,6 @@ class ImportDossiersJob(BaseANJob):
def
run
(
app
,
force
=
False
,
file
=
None
):
def
run
(
app
,
force
=
False
,
file
=
None
):
ImportDossiersJob
(
ImportDossiersJob
(
app
,
app
,
u
'AN: dossiers législatifs'
,
'AN: dossiers législatifs'
,
'/travaux-parlementaires/dossiers-legislatifs'
'/travaux-parlementaires/dossiers-legislatifs'
)
.
run
(
force
,
file
)
)
.
run
(
force
,
file
)
parlapi/jobs/an/reunions.py
View file @
3ca5e5d4
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
from
..base
import
BaseANJob
from
..base
import
BaseANJob
from
..utils
import
ijson_items
from
..utils
import
ijson_items
from
...models.an
import
(
Organe
,
Acteur
,
Reunion
,
ODJItem
,
ODJPoint
,
from
...models.an
import
(
Organe
,
Acteur
,
Dossier
,
Reunion
,
ODJItem
,
ODJPoint
,
OrganeReunion
,
ActeurReunion
)
OrganeReunion
,
ActeurReunion
)
class
ImportReunionsJob
(
BaseANJob
):
class
ImportReunionsJob
(
BaseANJob
):
...
@@ -23,7 +23,7 @@ class ImportReunionsJob(BaseANJob):
...
@@ -23,7 +23,7 @@ class ImportReunionsJob(BaseANJob):
self
.
save_reunion
(
obj
)
self
.
save_reunion
(
obj
)
def
save_reunion
(
self
,
json
):
def
save_reunion
(
self
,
json
):
self
.
current
=
u
'Reunion
%
s'
%
json
[
'uid'
]
self
.
current
=
'Reunion
%
s'
%
json
[
'uid'
]
data
=
{
data
=
{
'acteurs'
:
[],
'acteurs'
:
[],
...
@@ -75,13 +75,13 @@ class ImportReunionsJob(BaseANJob):
...
@@ -75,13 +75,13 @@ class ImportReunionsJob(BaseANJob):
acts
=
[
acts
]
acts
=
[
acts
]
for
act
in
acts
:
for
act
in
acts
:
ar
=
ActeurReunion
(
relation
=
u
'demandeur'
)
ar
=
ActeurReunion
(
relation
=
'demandeur'
)
ar
.
acteur
=
self
.
save
(
Acteur
,
act
[
'acteurRef'
])
ar
.
acteur
=
self
.
save
(
Acteur
,
act
[
'acteurRef'
])
data
[
'acteurs'
]
.
append
(
ar
)
data
[
'acteurs'
]
.
append
(
ar
)
# SRSLY WTF !? I don't want to live on this planet anymore D:<
# SRSLY WTF !? I don't want to live on this planet anymore D:<
if
json
.
get
(
'demandeur'
,
None
)
and
'acteurRef'
in
json
[
'demandeur'
]:
if
json
.
get
(
'demandeur'
,
None
)
and
'acteurRef'
in
json
[
'demandeur'
]:
ar
=
ActeurReunion
(
relation
=
u
'demandeur'
)
ar
=
ActeurReunion
(
relation
=
'demandeur'
)
ar
.
acteur
=
self
.
save
(
Acteur
,
json
[
'demandeur'
][
'acteurRef'
])
ar
.
acteur
=
self
.
save
(
Acteur
,
json
[
'demandeur'
][
'acteurRef'
])
data
[
'acteurs'
]
.
append
(
ar
)
data
[
'acteurs'
]
.
append
(
ar
)
...
@@ -91,12 +91,12 @@ class ImportReunionsJob(BaseANJob):
...
@@ -91,12 +91,12 @@ class ImportReunionsJob(BaseANJob):
orgs
=
[
orgs
]
orgs
=
[
orgs
]
for
org
in
orgs
:
for
org
in
orgs
:
or_
=
OrganeReunion
(
relation
=
u
'demandeur'
)
or_
=
OrganeReunion
(
relation
=
'demandeur'
)
or_
.
organe
=
self
.
save
(
Organe
,
org
[
'organeRef'
])
or_
.
organe
=
self
.
save
(
Organe
,
org
[
'organeRef'
])
data
[
'organes'
]
.
append
(
or_
)
data
[
'organes'
]
.
append
(
or_
)
if
json
.
get
(
'organeReuniRef'
,
None
):
if
json
.
get
(
'organeReuniRef'
,
None
):
or_
=
OrganeReunion
(
relation
=
u
'organeReuni'
)
or_
=
OrganeReunion
(
relation
=
'organeReuni'
)
or_
.
organe
=
self
.
save
(
Organe
,
json
[
'organeReuniRef'
])
or_
.
organe
=
self
.
save
(
Organe
,
json
[
'organeReuniRef'
])
data
[
'organes'
]
.
append
(
or_
)
data
[
'organes'
]
.
append
(
or_
)
...
@@ -107,7 +107,8 @@ class ImportReunionsJob(BaseANJob):
...
@@ -107,7 +107,8 @@ class ImportReunionsJob(BaseANJob):
if
isinstance
(
pris
,
dict
):
if
isinstance
(
pris
,
dict
):
pris
=
[
pris
]
pris
=
[
pris
]
for
p
in
pris
:
for
p
in
pris
:
ar
=
ActeurReunion
(
relation
=
u'participant'
,
presence
=
p
[
'presence'
])
ar
=
ActeurReunion
(
relation
=
'participant'
,
presence
=
p
[
'presence'
])
ar
.
acteur
=
self
.
save
(
Acteur
,
p
[
'acteurRef'
])
ar
.
acteur
=
self
.
save
(
Acteur
,
p
[
'acteurRef'
])
data
[
'acteurs'
]
.
append
(
ar
)
data
[
'acteurs'
]
.
append
(
ar
)
...
@@ -117,7 +118,7 @@ class ImportReunionsJob(BaseANJob):
...
@@ -117,7 +118,7 @@ class ImportReunionsJob(BaseANJob):
if
isinstance
(
pras
,
dict
):
if
isinstance
(
pras
,
dict
):
pras
=
[
pras
]
pras
=
[
pras
]
for
p
in
pras
:
for
p
in
pras
:
ar
=
ActeurReunion
(
relation
=
u
'auditionne'
)
ar
=
ActeurReunion
(
relation
=
'auditionne'
)
adata
=
{}
adata
=
{}
if
p
[
'uid'
][
'@xsi:type'
]
==
'IdPersonneExterne_type'
:
if
p
[
'uid'
][
'@xsi:type'
]
==
'IdPersonneExterne_type'
:
...
@@ -133,23 +134,24 @@ class ImportReunionsJob(BaseANJob):
...
@@ -133,23 +134,24 @@ class ImportReunionsJob(BaseANJob):
ar
.
acteur
=
self
.
save
(
Acteur
,
p
[
'uid'
][
'#text'
],
adata
)
ar
.
acteur
=
self
.
save
(
Acteur
,
p
[
'uid'
][
'#text'
],
adata
)
data
[
'acteurs'
]
.
append
(
ar
)
data
[
'acteurs'
]
.
append
(
ar
)
if
json
.
get
(
'ODJ'
,
None
):
if
json
.
get
(
'ODJ'
,
None
):
odj
=
json
[
'ODJ'
]
odj
=
json
[
'ODJ'
]
if
odj
.
get
(
'resumeODJ'
,
None
)
and
odj
[
'resumeODJ'
]
.
get
(
'item'
,
None
):
if
odj
.
get
(
'resumeODJ'
,
None
)
\
and
odj
[
'resumeODJ'
]
.
get
(
'item'
,
None
):
items
=
odj
[
'resumeODJ'
][
'item'
]
items
=
odj
[
'resumeODJ'
][
'item'
]
if
isinstance
(
items
,
basestring
):
if
isinstance
(
items
,
str
):
items
=
[
items
]
items
=
[
items
]
data
[
'items_odj'
]
=
[
ODJItem
(
item
=
i
)
for
i
in
items
]
data
[
'items_odj'
]
=
[
ODJItem
(
item
=
i
)
for
i
in
items
]
if
odj
.
get
(
'pointsODJ'
,
None
)
and
odj
[
'pointsODJ'
]
.
get
(
'pointODJ'
,
None
):
if
odj
.
get
(
'pointsODJ'
,
None
)
\
and
odj
[
'pointsODJ'
]
.
get
(
'pointODJ'
,
None
):
points
=
odj
[
'pointsODJ'
][
'pointODJ'
]
points
=
odj
[
'pointsODJ'
][
'pointODJ'
]
if
isinstance
(
points
,
dict
):
if
isinstance
(
points
,
dict
):
points
=
[
points
]
points
=
[
points
]
data
[
'points_odj'
]
=
[
self
.
save_point
(
p
)
for
p
in
points
]
data
[
'points_odj'
]
=
[
self
.
save_point
(
p
)
for
p
in
points
]
reunion
=
self
.
save
(
Reunion
,
json
[
'uid'
],
data
)
self
.
save
(
Reunion
,
json
[
'uid'
],
data
)
def
save_point
(
self
,
json
):
def
save_point
(
self
,
json
):
cur
=
self
.
current
cur
=
self
.
current
...
@@ -185,7 +187,7 @@ class ImportReunionsJob(BaseANJob):
...
@@ -185,7 +187,7 @@ class ImportReunionsJob(BaseANJob):
if
json
.
get
(
'dossierLegislatifsRefs'
,
None
):
if
json
.
get
(
'dossierLegislatifsRefs'
,
None
):
dossiers
=
json
[
'dossierLegislatifsRefs'
]
dossiers
=
json
[
'dossierLegislatifsRefs'
]
if
isinstance
(
dossier
,
dict
):
if
isinstance
(
dossier
s
,
dict
):
dossiers
=
[
dossiers
]
dossiers
=
[
dossiers
]
data
[
'dossiers'
]
=
[
self
.
save
(
Dossier
,
d
[
'dossierRef'
])
data
[
'dossiers'
]
=
[
self
.
save
(
Dossier
,
d
[
'dossierRef'
])
for
d
in
dossiers
]
for
d
in
dossiers
]
...
@@ -199,6 +201,6 @@ class ImportReunionsJob(BaseANJob):
...
@@ -199,6 +201,6 @@ class ImportReunionsJob(BaseANJob):
def
run
(
app
,
force
=
False
,
file
=
None
):
def
run
(
app
,
force
=
False
,
file
=
None
):
ImportReunionsJob
(
ImportReunionsJob
(
app
,
app
,
u
'AN: réunions'
,
'AN: réunions'
,
'/reunions/reunions'
'/reunions/reunions'
)
.
run
(
force
,
file
)
)
.
run
(
force
,
file
)
parlapi/jobs/an/scrutins.py
View file @
3ca5e5d4
...
@@ -3,16 +3,16 @@
...
@@ -3,16 +3,16 @@
from
..base
import
BaseANJob
from
..base
import
BaseANJob
from
..utils
import
ijson_items
from
..utils
import
ijson_items
from
...models.an
import
(
Organe
,
Legislature
,
Acteur
,
Mandat
,
Scrutin
,
Votant
,
from
...models.an
import
(
Organe
,
Legislature
,
Acteur
,
Mandat
,
Scrutin
,
Votant
,
ScrutinGroupe
)
ScrutinGroupe
)
class
ImportScrutinsJob
(
BaseANJob
):
class
ImportScrutinsJob
(
BaseANJob
):
positions
=
{
positions
=
{
'nonVotants'
:
u
'non-votant'
,
'nonVotants'
:
'non-votant'
,
'pours'
:
u
'pour'
,
'pours'
:
'pour'
,
'contres'
:
u
'contre'
,
'contres'
:
'contre'
,
'abstentions'
:
u
'abstention'
'abstentions'
:
'abstention'
}
}
def
__init__
(
self
,
app
,
name
,
url
):
def
__init__
(
self
,
app
,
name
,
url
):
...
@@ -30,7 +30,7 @@ class ImportScrutinsJob(BaseANJob):
...
@@ -30,7 +30,7 @@ class ImportScrutinsJob(BaseANJob):
self
.
save_scrutin
(
obj
)
self
.
save_scrutin
(
obj
)
def
save_scrutin
(
self
,
json
):
def
save_scrutin
(
self
,
json
):
self
.
current
=
u
'Scrutin
%
s'
%
json
[
'uid'
]
self
.
current
=
'Scrutin
%
s'
%
json
[
'uid'
]
sy
=
json
[
'syntheseVote'
]
sy
=
json
[
'syntheseVote'
]
gr
=
json
[
'ventilationVotes'
][
'organe'
][
'groupes'
][
'groupe'
]
gr
=
json
[
'ventilationVotes'
][
'organe'
][
'groupes'
][
'groupe'
]
...
@@ -60,11 +60,11 @@ class ImportScrutinsJob(BaseANJob):
...
@@ -60,11 +60,11 @@ class ImportScrutinsJob(BaseANJob):
'type_majorite'
:
json
[
'typeVote'
][
'typeMajorite'
],
'type_majorite'
:
json
[
'typeVote'
][
'typeMajorite'
],
}
}
s
crutin
=
s
elf
.
save
(
Scrutin
,
json
[
'uid'
],
data
)
self
.
save
(
Scrutin
,
json
[
'uid'
],
data
)
def
save_groupe
(
self
,
json
):
def
save_groupe
(
self
,
json
):
cur
=
self
.
current
cur
=
self
.
current
self
.
current
=
u
'
%
s > groupe
%
s'
%
(
cur
,
json
[
'organeRef'
])
self
.
current
=
'
%
s > groupe
%
s'
%
(
cur
,
json
[
'organeRef'
])
groupe
=
ScrutinGroupe
()
groupe
=
ScrutinGroupe
()
...
@@ -85,7 +85,7 @@ class ImportScrutinsJob(BaseANJob):
...
@@ -85,7 +85,7 @@ class ImportScrutinsJob(BaseANJob):
votants
=
[]
votants
=
[]
for
k
,
pos
in
self
.
positions
.
items
():
for
k
,
pos
in
self
.
positions
.
items
():
if
vote
[
'decompteNominatif'
]
.
get
(
k
,
None
):
if
vote
[
'decompteNominatif'
]
.
get
(
k
,
None
):
if
isinstance
(
vote
[
'decompteNominatif'
][
k
],
basestring
):
if
isinstance
(
vote
[
'decompteNominatif'
][
k
],
str
):
continue
continue
vs
=
vote
[
'decompteNominatif'
][
k
][
'votant'
]
vs
=
vote
[
'decompteNominatif'
][
k
][
'votant'
]
...
@@ -106,6 +106,6 @@ class ImportScrutinsJob(BaseANJob):
...
@@ -106,6 +106,6 @@ class ImportScrutinsJob(BaseANJob):
def
run
(
app
,
force
=
False
,
file
=
None
):
def
run
(
app
,
force
=
False
,
file
=
None
):
ImportScrutinsJob
(
ImportScrutinsJob
(
app
,
app
,
u
'AN: scrutins'
,
'AN: scrutins'
,
'/travaux-parlementaires/votes'
'/travaux-parlementaires/votes'
)
.
run
(
force
,
file
)
)
.
run
(
force
,
file
)
parlapi/jobs/base.py
View file @
3ca5e5d4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
from
datetime
import
datetime
from
datetime
import
datetime
from
collections
import
defaultdict
from
collections
import
defaultdict
import
copy
import
os
import
os
import
traceback
import
traceback
from
zipfile
import
ZipFile
from
zipfile
import
ZipFile
...
@@ -46,16 +45,16 @@ class BaseJob(object):
...
@@ -46,16 +45,16 @@ class BaseJob(object):
self
.
_updated
=
defaultdict
(
lambda
:
0
)
self
.
_updated
=
defaultdict
(
lambda
:
0
)
def
debug
(
self
,
msg
):
def
debug
(
self
,
msg
):
self
.
app
.
logger
.
debug
(
u
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
self
.
app
.
logger
.
debug
(
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
def
info
(
self
,
msg
):
def
info
(
self
,
msg
):
self
.
app
.
logger
.
info
(
u
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
self
.
app
.
logger
.
info
(
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
def
warn
(
self
,
msg
):
def
warn
(
self
,
msg
):
self
.
app
.
logger
.
warn
(
u
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
self
.
app
.
logger
.
warn
(
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
def
error
(
self
,
msg
):
def
error
(
self
,
msg
):
self
.
app
.
logger
.
error
(
u
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))
self
.
app
.
logger
.
error
(
'<
%
s>
%
s'
%
(
self
.
job_name
,
msg
))