Skip to content

Instantly share code, notes, and snippets.

@woods
Created August 5, 2009 16:22
Show Gist options
  • Save woods/162792 to your computer and use it in GitHub Desktop.
Save woods/162792 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Query twitter for all recent tweets by West Arete Computing and write them
# to a JSON file.
require 'rubygems'
require 'twitter'
require 'active_support'
# The users from whom we should fetch tweets tagged with #westarete
USERS = %w( creativeembassy coffeencoke westaretescott )
# Get all tweets from user westarete.
westarete = Twitter::Search.new.from('westarete').fetch.results
# Get all tweets tagged #westarete from each of the users.
users = USERS.map { |user| Twitter::Search.new.from(user).hashed('westarete').fetch.results }
# Combine the results and sort by timestamp.
tweets = [westarete, users].flatten.sort_by { |tweet| tweet.created_at.to_time }.reverse
# Convert to json.
File.open('westarete_tweets.json', 'w') { |f| f.write(tweets.to_json) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment