Created
August 8, 2008 21:49
-
-
Save eric/4629 to your computer and use it in GitHub Desktop.
Making it simple to provide input for http://wordle.net/create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Created by Eric Lindvall <[email protected]> | |
# | |
# Making it simple to provide input for http://wordle.net/create | |
# | |
# | |
require 'rubygems' | |
gem 'mechanize' | |
require 'mechanize' | |
def collect_entries(page) | |
page.parser.search('.entry-content').collect do |span| | |
span.search('a').remove | |
span.inner_text.strip.gsub(/(^|\s+)@($|\W+)/, '') | |
end | |
end | |
def gather_all_tweets(username, password) | |
agent = WWW::Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
page = agent.get('http://twitter.com/account/archive') | |
login_form = page.forms.action('https://twitter.com/sessions').first | |
login_form['username_or_email'] = username | |
login_form['password'] = password | |
login_form.submit | |
page = agent.get('http://twitter.com/account/archive') | |
unless page.forms.action('https://twitter.com/sessions').first.nil? | |
raise "The username or password was invalid" | |
end | |
text = collect_entries(page) | |
while link = page.links.text(/Older/).first | |
page = link.click | |
text += collect_entries(page) | |
end | |
text.flatten | |
end | |
username, password = ARGV[0], ARGV[1] | |
puts gather_all_tweets(username, password).join("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment