A hack based on Jigsaw's Perspective API. It is a simple dashboard that visualizes toxic langauge in tweets and allows you to jump into the conversation on twitter. Just enter someone's twitter handle to see how much / if they are the target of toxicity and harassment.
- python 3.6+
- Redis (right now only used for caching but hopefully to be used for a queue for intermediate results/loading in the near future)
- Your own keys for Twitter and the Perspective API (note: this app currently uses an app-wide key for twitter (no oauth for users) and hence there are security and rate-limit implications to keep in mind).
The main libraries being used are Dash, a python data viz library that wraps up flask, d3, and React, and pandas for data manipulation/filtering. Tweepy is used for pulling tweets and asyncio/aiohttp is used for parallizing requests to the perspective api.
For now, I'll assume you're on a mac:
-
Make sure you have python 3.6+:
brew update, and thenbrew upgrade pythonorbrew install python(this should install python 3, not 2). -
Install redis with homebrew:
brew install redisandbrew services start redis. -
Activate a virtualenv and install python dependencies:
pip install -r requirements -
Set environment variables for your keys:
export PERSPECTIVE_KEY=[your-key-here]
export TWITTER_KEY=[your-key-here]
export TWITTER_SECRET=[your-key-here]-
Run locally with
python app.pyfrom the project directory and go to http://localhost:8050/ in your browser. -
You could also run locally with Gunicorn, e.g.:
gunicorn app:server -w 4 -k gevent
One of the easiest and free-est ways to deploy is with Heroku (though it shouldn't be too much work to put it on, for example, Google App Engine).
-
Create a Heroku account, download the CLI, and run
heroku loginto auth. -
Hook up Heroku with
heroku createin the project directory and connect a free-tier instance of Redis to your Heroku project withheroku addons:create heroku-redis:hobby-dev -a harassment-dashboard. -
Set environment variables (with the same names as above) for your keys in the heroku dashboard or in terminal. The REDIS_URL key will be set automatically by Heroku.
-
And finally, deploy with
git push heroku master. Go to the address generated to confirm the app is deployed. You can adjust Gunicorn settings in the Procfile. And you can see logs for your project withheroku logs -a harassment-dashboard.

