Gary-Community-Ventures / benefits-api

MIT License
4 stars 4 forks source link

MyFriendBen

MyFriendBen was created by Gary Community Ventures, a Denver-based organization. We co-designed MyFriendBen with a group of Colorado families who are participating in a direct cash assistance program. Families told us it was difficult and time-consuming to know what benefits they were entitled to. We are defining “benefits” as public benefits (includes city, county, state and federal), tax credits, financial assistance, nonprofit supports and services. MyFriendBen only includes benefits and tax credits with an annual value of at least $300 or more a year.

Taking inspiration from AccessNYC, and connecting with PolicyEngine's API for benefits calculation, we built out a universal benefits screener with the goal to increase benefit participation rates by making key information - like dollar value and time to apply - more transparent, accessible, and accurate. The platform is currently live in Colorado and has been tested with over 40 benefits.

This is the repository for the backend Python/Django rules engine that takes household demographic data and returns benefits eligibility and estimated values. The frontend repository can be accessed here.

Set Up Benefits-API (back-end part)

Clone the project: git clone https://github.com/Gary-Community-Ventures/benefits-api.git

Create virtual environment: python -m venv venv

Install dependencies: pip install -r requirements.txt


Set up PostgreSQL

Download PostgreSQL:

Windows: https://www.postgresql.org/download/windows/

Mac: https://www.postgresql.org/download/windows/


Create user and database:

Login to pgadmin

Create a new user and password.

Create a database and give the user permissions.

https://www.guru99.com/postgresql-create-alter-add-user.html


Set up .env:

Create a .env file in the backend root directory


Add the following environment variables:


Migrate database and start server:

Migrate python manage.py migrate

Create super user: python manage.py createsuperuser . Then fill out fields as prompted.

Run server: python manage.py runserver


Add Programs:

MyFriendBen programs are stored in the database. The quick_start command will create the initial programs. These generated programs are not fully accurate to the actual programs. For example, the quick start command will mark every program as having no legal status requirements.

python manage.py quick_start


Import Translations:

MyFriendBen uses google translate to translate MyFriendBen into other languages. If a translation is incorrect, it is possible to manually edit the translations.

Download translations:

Download: Translations

Import translations:

python manage.py bulk_import < [PATH TO FILE]


Get API Key:

An API key is needed for the front end to connect to the backend.

Create group :

Go to http://localhost:8000/admin/auth/group/

Create a group with:

image

Create API user:

Go to http://localhost:8000/admin/authentication/user/

Create a new user and add the group that was just created.

Create API key:

Go to http://localhost:8000/admin/authtoken/tokenproxy/

Create a token and add the user that was just created.


Set up Google Cloud Services:

The API currently uses 2 google cloud services: Cloud Translation API & Google Sheets API

Sign up:

Visit the google cloud services sign up page and click on “TRY FOR FREE”

image

Add Services:

The next step is to go the google services APIs library page and add and enable the required services:

image

Create Credentials:

Go to the “Credentials” tab and add a new “Service account”

image

Generate Keys:

After adding the service account, select it and go to its page. And from the “KEYS” tab press the “ADD KEY” and “Create new key” and select the type of key to be JSON.

image

Format JSON:

The generated JSON is going to be something like so:

{ 

  "type":"service_account",

  "project_id":"[YOUR_PROJECT_ID]",

  "private_key_id":"[PRIVATE_KEY_ID]",

  "private_key":"[PRIVATE_KEY]",

  "client_email":"[CLIENT_EMAIL]",

  "client_id":"[CLIENT_ID]",

  "auth_uri":"[AUTH_URI]",

  "token_uri":"[TOKEN_URI]",

  "auth_provider_x509_cert_url":"[AUTH_PROVIDER_URL]",

  "client_x509_cert_url":"[CLIENT_CERT_URL]",

  "universe_domain":"[UNIVERSE_DOMAIN]" 

}

Though in order for the .env file to make use of this JSON object properly it needs to be formatted so that everything is in one line, like so:

{"type": "service_account", "project_id": "[YOUR_PROJECT_ID]"}

A tool like this can be used to make the json into the correct format: https://www.text-utils.com/json-formatter/