Created
March 8, 2012 23:40
-
-
Save samchandra/2004171 to your computer and use it in GitHub Desktop.
Twitter Timeline and Facebook Pages Feed Aggregator with Ruby
This file contains hidden or 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 'bundler/setup' | |
require 'time' | |
require 'date' | |
require 'twitter' | |
require 'fb_graph' | |
require 'pp' | |
require 'json' | |
t_results = Twitter.user_timeline("your_user").map do |tweet| | |
id_str = tweet.id.to_s | |
utime = tweet.created_at.to_i | |
text = tweet.text | |
url = "http://#{text.split('http://').last}" | |
t_url = "http://mobile.twitter.com/your_user/status/#{id_str}" | |
{:id => id_str, | |
:text => text, | |
:picture => url, | |
:s_url => t_url, | |
:utime => utime | |
} | |
end | |
app_id = "your_app_id" | |
app_secret = "your_app_secret" | |
page_id = "your_app_page_id" | |
my_app = FbGraph::Application.new(app_id) | |
acc_tok = my_app.get_access_token(app_secret) | |
page = FbGraph::Page.fetch(page_id, :access_token => acc_tok) | |
# puts page.feed.count | |
f_result = page.feed.map do |item| | |
{:id => item.identifier, | |
:text => item.message, | |
:picture => item.picture, | |
:s_url => item.link, | |
:utime => item.created_time.to_i | |
} | |
end | |
# combine result and place latest on top | |
total_result = t_results.concat(f_result).sort_by{|e|e[:utime]}.reverse | |
File.open("combined_feed.json", "w") do |f| | |
f.puts ({:feeds => total_result, :count => total_result.count}.to_json) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment