Package: tlfp
the-law-factory-parserData generator forthe-law-factory project(http://www.LaFabriqueDeLaLoi.fr)Code used to generate the API available at:http://www.LaFabriqueDeLaLoi.fr/api/Install the dependenciesYou should set up a dedicated virtualenv with Python 3.5+:virtualenv-p$(whichpython3)venvsourcevenv/bin/activateUsing Pypy can seriously boost performance. You can easily install it and create a virtualenv with it for instance byinstalling Pyenv:pyenvinstallpypy3.5-6.0.0
pyenvvirtualenvpypy3.5-6.0.0lafabrique
pyenvactivatelafabriqueThen with your choice of virtualenv activated, install the dependencies:sudoaptinstalllibxml2-devlibxslt-dev# necessary for lxmlpipinstall--upgradesetuptoolspip# not necessary but always a good ideapipinstall-e.
pipinstall-Urrequirements.txt# to get the latest version of those dependenciesGenerate data for one billsearch for thebill's procedure page on Senat.frorAssemblee-nationale.fr.executetlfp-parsescript using the procedure page: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-614Development options--debug,--enable-cacheand--only-promulgatedcan also be used.Generate data for many billsTo generate all bills from 2008, you can pipe a list of ids or urls intotlfp-parse-many.A convenient way to do so is to usesenapy:senapy-cli doslegs_urls --min-year=2008 | tlfp-parse-many data/Seesenapy-cli doslegs_urlshelp for more options. You can also useanpywithanpy-cli doslegs_urls.Serve bills locally forThe Law Factory websiteFirst, 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 vizFinally, 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 installhttp-serverwith 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 --corsGenerate git version for a billWork In ProgressYou can export all your bills as git repositories:python tlfp/tools/make_git_repos.py git_exportOther things you can doparse a sénat dosleg:senapy-cli parse pjl15-610parse an AN dosleg:anpy-cli parse http://www.assemblee-nationale.fr/13/dossiers/deuxieme_collectif_2009.aspparse all the sénat doslegs:senapy-cli doslegs_urls | senapy-cli parse_many senat_doslegs/parse all the AN doslegsanpy-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.svgYou can explore the related projectshereTestsTo run the tests, you can follow the.travis.ymlfile.git clone https://github.com/regardscitoyens/the-law-factory-parser-test-cases.git
python tests/test_regressions.py the-law-factory-parser-test-casesIf you modify something, best is to regenerate the test-cases with the--regenflag:python tests/test_regressions.py the-law-factory-parser-test-cases --regenTo make the tests faster, you can also use the--enable-cacheflag.
To clear the cache, you can remove the directory returned bylawfactory_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.jsonfiles.You can also watch for parts of the code not yet covered by the tests:First, installcoverage:pip install coverageThen, you can executebash coverage.shThen, the report is inhtmlcov/index.htmlCreditsThis work, a collaboration betweenRegard Citoyens,médialab Sciences PoandCEE 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 athttps://lafabriquedelaloi.fr/a-propos.html