/jarbas

API to return metadata of reimbursements made by 🇧🇷 Chamber of Deputies

Primary LanguageElmMIT LicenseMIT

Jarbas — a tool for Serenata de Amor

Build Status Code Climate Coverage Status Updates

Jarbas is a tool for Serenata de Amor contributors.

JSON API endpoints

Documents

In Jarbas context a Document refers to a document (a reimbursement claim) from CEAP.

GET /api/document/

This endpoint lists Document objects and it accepts any field (and any combination among them) as a filter. For example:

GET /api/document/?year=2015&state=RS&congressperson_id=42

These are the fields that can be combined for filtering purposes:

  • applicant_id
  • cnpj_cpf
  • congressperson_id
  • document_id
  • document_type
  • month
  • party
  • reimbursement_number
  • state
  • subquota_group_id
  • subquota_number
  • term
  • year

GET /api/receipt/<Document.pk>

This endpoint gets the URL to the digitalized version of the receipt of a Document. It returns { url: null } if the digitalized version is not available. The endpoint expects a Document.pk (i.e. the primary key of the Document object).

Supplier

A supplier is a Brazilian company in which congressperson have made expenses and claimed for reimbursement.

GET /api/supplier/<Supplier.cnpj>

This endpoit gets the info we have for a specific supplier. The endpoint expects a Supplier.cnpj (i.e. the CNPJ of a Supplier object). It returns 404 if the supplier is not found.

Install

Requirements

The app is based in Python 3.5 and Node.js 6. Once you have pip and npm available, install the dependencies:

npm i
python -m pip install -r requirements-dev.txt

Minor details on requirements:

  • lzma: In some Linux distros lzma is not installed by default. You can check whether you have it or not with $ python -m lzma. In Debian based systems you can fix that with $ apt-get install liblzma-dev but you mihght have to re-compile your Python.
  • elm-make: If elm-make is not available in your path, or if the elm-make version differs from the one required by this project, set ELM_MAKE_BIN environment variable pointing to where the proper elm-make binary is (probably node_modules/.bin/elm-make)
  • psycopg2: The requirements.txt file is prepared to use PostgresSQL and psycopg2 might fail if you don't have Postgres installed locally.

Settings

Copy contrib/.env.sample as .env in the project's root folder and adjust your settings. These are the main environment settings:

Django settings

Database

Amazon S3 settings

  • AMAZON_S3_BUCKET (str) Name of the Amazon S3 bucket to look for datasets (e.g. serenata-de-amor-data)
  • AMAZON_S3_REGION (str) Region of the Amazon S3 (e.g. s3-sa-east-1)
  • AMAZON_S3_DATASET_DATE (str) Datasets file name prefix of CEAP datasets from Serenata de Amor (e.g. 2016-08-08 for 2016-08-08-current-year.xz)
  • AMAZON_S3_SUPPLIERS_DATE (str) Datasets file name prefix for suppliers dataset (e.g. 2016-08-08 for 2016-08-08-companies.xz)

Google Analytics

  • GOOGLE_ANALYTICS (str) Google Analytics tracking code (e.g. UA-123456-7)

Migrations

Once you're done with requirements, dependencies and settings, create the basic structure at the database (and if you wish, create a super-user for you, so you can use Django Admin later):

python manage.py migrate
python manage.py createsuperuser

Load data

Now you can load the data from our datasets:

python manage.py loaddatasets

Use python manage.py loaddatasets --help to check options on limiting the number of documents to be loaded from the datasets.

Generate static files

We generate assets through webassets and we serve static files through WhiteNoise, thus you might have to run:

python manage.py assets build
python manage.py collectstatic

Ready?

Not sure? Run python manage.py check and python manage.py test just in case.

Ready!

Run the server with python manage.py runserver and load localhost:8000 in your favorite browser.

If you created a super-user account, you can also use Django Admin at /admin/.

License

Licensed under the MIT License.