Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open twitter favourite tweets links in new tabs (Mac OS X only)
#!/usr/bin/env ruby
##############################
# WARNING
# Will unfavourite your tweets
#
##############################
require 'twitter'
# require 'redis'
# username of user favourites to process
TWITTER_USERNAME = 'FILL_ME_IN'
# limit of favourited tweets to process (may be more links opened)
FAVOURITE_LIMIT = 30
# twitter app credentials
CONSUMER_KEY = 'FILL_ME_IN'
CONSUMER_SECRET = 'FILL_ME_IN'
YOUR_OAUTH_TOKEN = 'FILL_ME_IN'
YOUR_OAUTH_TOKEN_SECRET = 'FILL_ME_IN'
# lower case list of hosts to ignore
HOST_IGNORE_LIST = [
'www.techmeme.com' #ignored because direct article link is desired
]
# redis = Redis.new
Twitter.configure do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
linkList = []
options = {count: FAVOURITE_LIMIT, include_entities: 1}
# fetch twitter favourites and process results
Twitter.favorites(TWITTER_USERNAME, options).each do |fav|
# save favourited tweet ids into redis (for nostalgia)
# redis.sadd 'twitterfavouritehistory', fav.id
# process tweet links and add to list of links to open
fav.expanded_urls.each do |url|
uri = URI.parse(url) rescue nil
# add to list only if link host is not ignored
linkList << url unless uri.host && HOST_IGNORE_LIST.include?(uri.host)
end
# remove tweet from twitter favourites
Twitter.unfavorite(fav.id)
end
# reverse link list to open oldest in left most tabs
system "open #{linkList.reverse.join(' ')}" unless linkList.empty?
# delay remain count to allow of latency inaccuracies
# sleep 2 #seconds
# system %(growlnotify -t "Twitter Favourite Reader" -m "#{Twitter.favorites.count} favourites remain")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment