Created
June 19, 2013 13:37
-
-
Save endorfin/5814391 to your computer and use it in GitHub Desktop.
15min ruby script to post googleplus 2 twitter
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
require 'rubygems' | |
require 'fileutils' | |
require 'feedzirra' | |
require 'googl' | |
require 'twitter' | |
Twitter.configure do |config| | |
config.consumer_key = CONSUMER_KEY | |
config.consumer_secret = CONSUMER_SECRET | |
config.oauth_token = OAUTH_TOKEN | |
config.oauth_token_secret = OAUTH_TOKEN_SECRET | |
end | |
# feed | |
feed_url = GPLUSRSS_COM_FEED_URL # 'http://gplusrss.com/rss/feed/23a27154ed6e2d4dc89d1df554ef585651c19ecb32244' | |
feed = Feedzirra::Feed.fetch_and_parse(feed_url) | |
log_file = '/tmp/gplus2twitter.log' | |
FileUtils.touch(log_file) | |
lines = File.readlines(log_file) | |
File.open(log_file, 'w') {} | |
for entry in feed.entries.reverse! | |
unless lines.map{|line| line.strip == entry.url}.include?(true) | |
url = Googl.shorten(entry.url) | |
short_url = url.short_url | |
text = entry.title.gsub(/\t+/, " ").gsub(/\s+/, " ").strip | |
puts tweet = "#{short_url} ... #{text}" | |
Twitter.update(tweet) | |
end | |
File.open(log_file, 'a') {|f| f.write("#{entry.url}\n") } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment