Skip to main content

Data generator for the-law-factory project lafabriquedelaloi.fr

Project description

the-law-factory-parser

Build Status Coverage Status

Data generator for the-law-factory project (http://www.LaFabriqueDeLaLoi.fr)

Code used to generate the API available at: http://www.LaFabriqueDeLaLoi.fr/api/

Install the dependencies

You should set up a dedicated virtualenv with Python 3.5+:

virtualenv -p $(which python3) venv
source venv/bin/activate

Using Pypy can seriously boost performance. You can easily install it and create a virtualenv with it for instance by installing Pyenv:

pyenv install pypy3.5-6.0.0
pyenv virtualenv pypy3.5-6.0.0 lafabrique
pyenv activate lafabrique

Then with your choice of virtualenv activated, install the dependencies:

sudo apt install libxml2-dev libxslt-dev # necessary for lxml
pip install --upgrade setuptools pip # not necessary but always a good idea
pip install -e .
pip install -Ur requirements.txt # to get the latest version of those dependencies

Generate data for one bill

tlfp-parse <url>

The data is generated in the "data" directory. You can change this default behavior by inputting a data path as extra argument: tlfp-parse <url> <dataDir>.

For example, to generate data about the "Enseignement supérieur et recherche" bill:

tlfp-parse http://www.senat.fr/dossier-legislatif/pjl12-614.html
ls data/pjl12-614/

You can also use directly Senate's ids such as: tlfp-parse pjl12-614

Development options --debug, --enable-cache and --only-promulgated can also be used.

Generate data for many bills

To generate all bills from 2008, you can pipe a list of ids or urls into tlfp-parse-many.

A convenient way to do so is to use senapy:

senapy-cli doslegs_urls --min-year=2008 | tlfp-parse-many data/

See senapy-cli doslegs_urls help for more options. You can also use anpy with anpy-cli doslegs_urls.

Serve bills locally for The Law Factory website

First, you need to build data for all desired bills.

Then generate the files required by the frontend:

python tlfp/generate_dossiers_csv.py data/       # generates home.json and dossiers_promulgues.csv used by the searchbar
python tlfp/tools/assemble_procedures.py data/   # generates dossiers_n.json files used by the Navettes viz

Finally, serve the data directory however you like. For instance, you can serve it on a specific port with a simple http server like nodeJs', in which case, you'll need to enable cors: just install http-server with npm and run it in data directory on a given port (8002 in the example):

npm install -g http-server
cd data & http-server -p 8002 --cors

Generate git version for a bill

Work In Progress

You can export all your bills as git repositories: python tlfp/tools/make_git_repos.py git_export

Other things you can do

  • parse a sénat dosleg: senapy-cli parse pjl15-610
  • parse an AN dosleg: anpy-cli parse http://www.assemblee-nationale.fr/13/dossiers/deuxieme_collectif_2009.asp
  • parse all the sénat doslegs: senapy-cli doslegs_urls | senapy-cli parse_many senat_doslegs/
  • parse all the AN doslegs anpy-cli doslegs_urls | anpy-cli parse_many an_doslegs/
  • generate a graph of the steps: python tlfp/tools/steps_as_dot.py data/ | dot -Tsvg > steps.svg

You can explore the related projects here

Tests

To run the tests, you can follow the .travis.yml file.

git clone https://github.com/regardscitoyens/the-law-factory-parser-test-cases.git
python tests/test_regressions.py the-law-factory-parser-test-cases

If you modify something, best is to regenerate the test-cases with the --regen flag:

python tests/test_regressions.py the-law-factory-parser-test-cases --regen

To make the tests faster, you can also use the --enable-cache flag. To clear the cache, you can remove the directory returned by lawfactory_where_is_my_cache. To update the meta-infos (ex: a new political group was added), you need to clear the test-cases directory of all the root .json files.

You can also watch for parts of the code not yet covered by the tests:

  • First, install coverage: pip install coverage
  • Then, you can execute bash coverage.sh
  • Then, the report is in htmlcov/index.html

Credits

This work, a collaboration between Regard Citoyens, médialab Sciences Po and CEE Sciences Po, is supported by a public grant overseen by the French National Research Agency (ANR) as part of the "Investissements d'Avenir" program within the framework of the LIEPP center of excellence (ANR11LABX0091, ANR 11 IDEX000502).

More details at https://lafabriquedelaloi.fr/a-propos.html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tlfp-0.0.3.tar.gz (68.9 kB view details)

Uploaded Source

Built Distribution

tlfp-0.0.3-py3-none-any.whl (93.9 kB view details)

Uploaded Python 3

File details

Details for the file tlfp-0.0.3.tar.gz.

File metadata

  • Download URL: tlfp-0.0.3.tar.gz
  • Upload date:
  • Size: 68.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

File hashes

Hashes for tlfp-0.0.3.tar.gz
Algorithm Hash digest
SHA256 573d2547294d735048ff1b0dbaa36ab7eede8d6e2b43cd59adc9c79240ff7605
MD5 f743388eeeea1986cab7f36d8ee21ed9
BLAKE2b-256 0fbd2c2cee1aef5b166376f0440c4ad34c638dde798a5b7de6faa77529c34a0f

See more details on using hashes here.

File details

Details for the file tlfp-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: tlfp-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 93.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

File hashes

Hashes for tlfp-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 63dd1f270b30b2f7c20394e287d7c1ce7d414a23d1f396563ed08b88939b1fb4
MD5 8e2fb7cf409ab454bf1d8e16ee977c5a
BLAKE2b-256 99efac6db508dd39c7ef46ce55c512ab5cf367a929ab727a81951f4e448761c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page