staterepme/State-Gov-Tracker — pull request #15 by notthatbreezy (2013-04-13 17:25:50+00:00)
Title: Easy loading of twitter handles and updating tweets for legislators

This pull request adds functionality for easily loading twitter handles for legislators via a bulk upload from a CSV and updating tweets for legislators via custom django-admin commands.

A few new settings are available in the `ansible_vars.example.yml` file for twitter API keys, tokens, and secrets. These are required to update tweets for legislators. You can obtain them at [Twitter's developer page](https://dev.twitter.com/).

The workflow for enabling downloading tweets is as follows.
1. Deploy project as normal, following the instructions in the Readme.
2. SSH into the VM, activate the virtualenv for the project.
3. Navigate to the project app directory.
4. Run `python manage.py load_leg_data <2 letter state abbreviation>` with the 2 letter state abbreviation you are interested in. This will load legislators from the specified state from OpenStates into the Postgres database for your staterep instance.
5. Create (or use the example file for PA) a CSV that has atleast 2 columns: `legid` and `twitter` that has the unique legislator id used in the Officials table and the Twitter handles for legislators. Each row in the CSV should be a legislator.
6. Run `python manage.py load_twitter_handles ` where you specify the path to the CSV that you created in the previous step. This loads all twitter handles into the database.
7. Run `python manage.py update_tweets`. This will download recent tweets for all the twitter handles you downloaded. Be aware - this is rate limited so if you do this too often you will hit the limit and have to wait to do it again.

There is also some cleaning up of existing code - specifically the following.
+ Update the `model.py` entry for tweets to use an actual timestamp field. This is the correct way to be dealing with times.
+ Eliminating the custom primary key column from the tweets model - this was causing some issues with Postgres; Django will create an ID field automatically that works well.

There is an example CSV for PA legislators and their twitter handles in the new `/raw_data/twitter/` folder as well.