Initially copied from Illinois Sunshine.
Install OS level dependencies:
- Python 3.4
- PostgreSQL 9.4 +
- MySQL client libraries + development headers
- Ubuntu Xenial:
libmysqlclient-devpackage - Debian Stretch:
libmariadbclient-devpackage - Fedora 26/CentOS 7:
mariadb-develpackage - OpenSUSE Leap 42.3:
libmysqlclient-develpackage - OS X Sierra:
mysqlhomebrew formula
- Ubuntu Xenial:
Docker environment on GitHub courtesy of @lottspot.
Install app requirements
We recommend using virtualenv and virtualenvwrapper for working in a virtualized development environment. Read how to set up virtualenv.
Once you have virtualenvwrapper set up (make sure to initialize as a Python 3 project),
mkdir leverage
cd leverage
git clone https://github.com/Lever-age/api.git
cd api
python3 -m virtualenv venv
source venv/bin/activate
pip install -r requirements.txtYou also need to create your own app_config.py file:
cp leverageapi/app_config.py.example leverageapi/app_config.pyIn app_config.py, put your Postgres user in DB_USER and password in DB_PW.
NOTE: Mac users might need this lxml workaround.
Afterwards, whenever you want to work on leverage-api, cd into the directory
source venv/bin/activateFor now, load the mysql files from the datadump directory. Load the tables.sql first, then data.sql
python runserver.py-
/api/races (same as /api/races?election_type=general&election_year=2018)
-
/api/races?race_id=2
-
/api/races?race_slug=governor
-
/api/candidates?race_id=2
-
/api/candidates?race_slug=governor
-
/api/candidates?candidate_id=4
-
/api/candidates?candidate_slug=thomas-w-wolf
-
/api/contributions?candidate_slug=thomas-w-wolf
-
/api/contributions?race_slug=governor
Before we can run the website, we need to create a database.
createdb leverage_apiThen, we run the etl.py script to download our data from the IL State Board of Elections and load it into the database.
python etl.py --download --load_data --recreate_viewsThis command will take between 15-45 min depending on your internet connection.
Doesn't do this: You can run etl.py again to get the latest data from the IL State Board of Elections. It is updated daily. Other useful flags are:
--download Downloading fresh data
--cache Cache downloaded files to S3
--load_data Load data into database
--recreate_views Recreate database views
--chunk_size CHUNK_SIZE Adjust the size of each insert when loading data
git clone git@github.com:datamade/leverage-api.git
cd leverage-api
# to run locally
python runserver.pynavigate to http://localhost:5000/
Uses MySQL for now...
While developing this, we noticed that PostgreSQL treats some names od individuals and organizations as stop words. We added a custom stop word list to the repo that can be used to make sure that these names will show up in search results.
- Create a symbolic link from the stop words list in this repo to the PostgreSQL shared directory (this example will work on Debian and Ubuntu):
sudo ln -s /path/to/this/repo/sunshine.stop /usr/share/postgresql/9.4/tsearch_data/sunshine.stopYou'll then need to change the STOP_WORD_LIST configuration in app_config.py to sunshine
- Eric van Zanten - developer
- Derek Eder - developer
If something is not behaving intuitively, it is a bug, and should be reported. Report it here: https://github.com/datamade/leverage-api/issues
- Fork the project.
- Make your feature addition or bug fix.
- Commit, do not mess with rakefile, version, or history.
- Send a pull request. Bonus points for topic branches.
Copyright (c) 2017 Code for Philly
Copyright (c) 2015 DataMade and Illinois Campaign for Political Reform. Released under the MIT License.