A collection of tools to help realize the organizing principles from the Indivisible Guide. Data sources include:
- You have python installed on your computer (comes by default), as well as the following libraries:
On Linux:
sudo apt-get install python-pip
sudo apt-get install python-virtualenv
On Mac OSX (with Homebrew):
brew install python-pip
sudo pip install virtualenv
- You will need to create and activate a virtualenv for the project as follows:
virtualenv venv
. venv/bin/activate
- Then install the dependencies:
pip install -r requirements.txt
- Request an API key from ProPublica
- Request an API key from Event Registry
- Request an API key for the Google Civic Information API
- [Optional] Request credentials from Twilio and a phone number and application sid:
- Add the following to a file (either name it
indivisible.cfg
, or modify the path in the instructions below):
PYTHONPATH=/path/to/repo/indivisible
FLASK_DEBUG=1
- Save the API keys to the same file:
PROPUBLICA_API_KEY="PASTE_API_KEY_HERE"
EVENT_REGISTRY_API_KEY="PASTE_API_KEY_HERE"
GOOGLE_CIVIC_INFORMATION_API="PASTE_API_KEY_HERE"
...
- Install DB of choice.
On Linux:
sudo apt-get install mysql-server
sudo mysql_secure_installation
mysqld --initialize
On Mac OSX: using SQLite is easiest. If you don't already have SQLite:
brew install sqlite
- Add database URI to configs:
For SQL:
DB_ADDR="mysql+pymysql://USER:PASSWORD@localhost/indivisible?charset=utf8"
For SQLite (to write to a file in /tmp
):
SQLALCHEMY_DATABASE_URI="sqlite:////tmp/indivisible.db"
- Initialize DB (note SQLite doesn't allow key constraint changes, so you may have to delete those lines):
pushd indivisible
env $(cat ../indivisible.cfg | xargs) python manage.py db upgrade
popd
env $(cat indivisible.cfg | xargs) python indivisible/indivisible.py
- Set up an Ubuntu VPS ala Digital Ocean
- Run the following to set up Apache:
sudo apt-get update
sudo apt-get install apache2 libapache2-mod-wsgi python-dev
sudo a2enmod wsgi
- Clone your repo into /var/www:
cd /var/wwww
git clone git@github.com:danieltahara/indivisible.git
- Repeat setup steps above.
- Add an app.conf as per Digital Ocean instructions:
sudo vim /etc/apache2/sites-available/indivisible.conf
WSGIPythonHome /var/www/indivisible/venv/bin
WSGIPythonPath /var/www/indivisible/venv/lib/python2.7/site-packages
<VirtualHost *:80>
ServerName YOUR_IP_ADDR_OR_DOMAIN
ServerAdmin YOUR_EMAIL_ADDR
WSGIScriptAlias / /var/www/indivisible/indivisible.wsgi
WSGIScriptReloading On
<Directory /var/www/indivisible/indivisible/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/indivisible/indivisible/static
<Directory /var/www/indivisible/indivisible/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog
${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog
${APACHE_LOG_DIR}/access.log
combined
</VirtualHost>
- Add a .wsgi file:
sudo vim /var/www/indivisible/indivisible.wsgi
import os
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/indivisible/")
# Add your keys here.
os.environ['PROPUBLICA_API_KEY'] = "XXXX"
from indivisible import app as application
from indivisible import initialize_app
initialize_app(application)
- Enable Virtual Host:
sudo a2ensite indivisible
- Restart apache
sudo service apache2 restart
- Optionally install SSL certs using Let's Encrypt:
sudo apt-get install python-letsencrypt-apache
letsencrypt apache