Fetch Tweet data from a cohort of screen names to rank based on number of replies. This is the code I used for publishing rankings of Massachusetts mayors, state representatives, state senators, statewide offices, and congressional delgation on abbett.org
- Twitter Rankings: Massachusetts State Representatives
- Twitter Rankings: Massachusetts State Senators
- Twitter Rankings: Massachusetts Mayors
- Twitter Rankings: Massachusetts Statewide & Congressional
- Apply for a Twitter developer account
- Once approved, create an app to generate a set of Twitter API keys and access tokens.
- Clone the
twitter-reply-ranking
repository to your computer. - Copy
credentials.orig.json
tocredentials.json
and fill in the fields with your new keys & tokens. - Install Ruby (if you don't have it already).
cd twitter-reply-ranking
gem install twitter
ruby twitter-reply-ranking.rb cohorts/ma_mayors.json templates/stats_mayors.html.erb
Replace the cohort
path with the cohort of your choice. Replace the templates
path with the output template of your choice.
...are each simply an array of JSON objects stored as .json
files in the cohorts
subdirectory. The only fields you absolutely need in each object are first
, last
, and screen_name
, though each output template makes its own demands for fields - you might see rendering errors if there's a mismatch. (There's definitely work to be done to make this more flexible/generic.)
...are each ERB files stored in the templates
subdirectory. They're currently a mix of Markdown and HTML, since that's what my Jekyll-driven website likes. Make them anything you like!
ruby twitter-reply-ranking.rb cohorts/ma_mayors.json templates/stats_mayors.html.erb
ruby twitter-reply-ranking.rb cohorts/ma_state_reps.json templates/stats.html.erb
ruby twitter-reply-ranking.rb cohorts/ma_state_senators.json templates/stats.html.erb
ruby twitter-reply-ranking.rb cohorts/ma_statewide.json templates/stats_statewide.html.erb
Post an issue in this repository, or message me on Twitter: @jonabbett
If you want to make new & interesting cohorts, post it in a pull request and I can include it.