Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created May 17, 2011 20:55
Show Gist options
  • Select an option

  • Save jedisct1/977377 to your computer and use it in GitHub Desktop.

Select an option

Save jedisct1/977377 to your computer and use it in GitHub Desktop.
Dump your Twitter favorites to a text file
#! /usr/bin/env ruby
# Just a small script I made to dump my favorite tweets to a text file.
# Because agrep in a text file is a super powerful and mega fast search engine :)
# Change USER and periodically run $ ruby twitter-favorites.rb >> favorites.txt
require 'twitter'
USER = '<your twitter user name>'
SINCE_ID_FILE = "#{ENV['HOME']}/.favorites_since_id"
page = 0
last_since_id = since_id = begin File.read(SINCE_ID_FILE).to_i rescue 1 end
favs = []
loop do
favs_page = Twitter.favorites(USER, since_id: since_id,
count: 200, page: page += 1)
break if favs_page.empty?
warn page
favs << favs_page.collect { |fav| fav.text.gsub(/[[:space:]]+/, ' ') }.reverse
last_since_id = favs_page.inject(last_since_id) do |last_since_id, fav|
fav.id > last_since_id ? fav.id : last_since_id
end
end
puts favs.reverse.join("\n\n")
File.open(SINCE_ID_FILE, 'w') { |f| f.write(last_since_id) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment