Skip to content

Instantly share code, notes, and snippets.

@ssig33
Created May 27, 2011 01:29
Show Gist options
  • Save ssig33/994477 to your computer and use it in GitHub Desktop.
Save ssig33/994477 to your computer and use it in GitHub Desktop.
フォローしてる人のタイムラインを RSS に変換するやつ
require "oauth"
require "json"
require "sinatra"
require "builder"
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
TOKEN = ''
SECRET =''
def consumer
OAuth::Consumer.new( CONSUMER_KEY, CONSUMER_SECRET, :site => 'http://api.twitter.com')
end
def access_token
OAuth::AccessToken.new(consumer, TOKEN, SECRET)
end
t = access_token
get "/:id" do
id = JSON.parse(t.get("/1/users/show.json?screen_name=#{params[:id]}").body)["id"]
@list = JSON.parse(t.get("/1/statuses/following_timeline.json?include_entities=1&include_available_features=1&contributor_details=true&user_id=#{id}").body)
builder :rss
end
__END__
@@ rss
xml.instruct!
xml.rss("version" => "2.0",
"xmlns:dc" => "http://purl.org/dc/elements/1.1/",
"xmlns:atom" => "http://www.w3.org/2005/Atom") do
xml.channel do
xml.title "Followings Timeline of #{params[:id]}"
xml.link "http://#{request.host_with_port}/#{params[:id]}"
xml.pubDate Time.now.rfc822
xml.description "SHIT"
xml.atom :link, "href" => "http://#{request.host_with_port}/#{params[:id]}", "rel" => "self", "type" => "application/rss+xml"
@list.each do |t|
xml.item do
xml.title "@#{t["user"]["screen_name"]} #{t["text"]}"
xml.link "http://twitter.com/#{t["user"]["screen_name"]}/status/#{t["id"]}"
xml.guid "http://twitter.com/#{t["user"]["screen_name"]}/status/#{t["id"]}"
xml.description "@#{t["user"]["screen_name"]} #{t["text"]}"
xml.pubDate Time.parse(t["created_at"]).rfc822
xml.dc :creator, @author
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment