Skip to content

Instantly share code, notes, and snippets.

@dersteppenwolf
Created October 24, 2012 23:25
Show Gist options
  • Save dersteppenwolf/3949572 to your computer and use it in GitHub Desktop.
Save dersteppenwolf/3949572 to your computer and use it in GitHub Desktop.
Generate a RSS of a Twitter feed using Ruby and Twitter API v1.1
require 'rubygems'
require 'twitter'
require 'builder'
client = Twitter::Client.new(
:consumer_key => "your consumer key",
:consumer_secret => "your consumer secret",
:oauth_token => "your oauth token",
:oauth_token_secret => "your oauth secret"
)
list_name = 'informadores─hispanos'
list_owner = "cobracultura"
maxStatuses = 100
timeline = client.list_timeline(list_owner, list_name,:count => maxStatuses )
xml = Builder::XmlMarkup.new( :indent => 2 )
xml.instruct!
xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
xml.channel do
xml.title "my list : "+list_name
xml.link "test"
xml.description "my list search"
timeline.reverse.each do |status|
xml.item do
xml.guid status.id
xml.author status.user.name
xml.title status.text
xml.link "https://twitter.com/"+status.user.screen_name+"/status/"+status.id.to_s()
xml.description status.text
xml.pubDate status.created_at
end
end
end
end
File.open("output.rss", "w") do |f|
f.write(xml.target.gsub("<target/>", ""))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment