DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

RSS Twitter Bot

03.22.2007
| 23007 views |
  • submit to reddit
        Republish an RSS feed on a twitter account. This was the source I used to run the <a href="http://twitter.com/woot">Woot Twitter Bot</a> before they took it over.

require 'rubygems'
require 'active_record'
require 'simple-rss'
require 'open-uri'
require 'twitter'

#twitter account to post to
twitter_email = "yourtwitteremail@bla.com"
twitter_password = "secret"

#rss feed to post
rss_url = "http://yoursite.com/index.xml"
rss_user_agent = "http://twitter.com/yourbot"

#sqlite db
path_to_sqlite_db = "/PATH/TO/db.sqlite"


ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false

ActiveRecord::Base.establish_connection(
    :adapter => "sqlite3",
    :dbfile  => path_to_sqlite_db
)

#uncomment this section the first time to create the table
#
#ActiveRecord::Schema.define do
#    create_table :item do |table|
#        table.column :title, :string
#        table.column :link, :string
#    end
#end

class Item < ActiveRecord::Base
  def to_s
    "#{self.title[0..(130-self.link.length)]} - #{self.link}"
  end
end

#run the beast
rss_items = SimpleRSS.parse open(rss_url ,"User-Agent" => rss_user_agent)

for item in rss_items.items
  Item.transaction do
    unless existing_item = Item.find(:all, :conditions => ["link=?", item.link]).first
      twitter ||= Twitter::Base.new(twitter_email, twitter_password)
      new_item = Item.create(:title => item.title, :link => item.link) 
      twitter.post(new_item.to_s)
    end
  end
end

Run this once with the lines uncommented to create the DB, then slap it in your crontab.    

Comments

Maydi Lee replied on Thu, 2014/03/06 - 12:31am

 

Even just in case a person really wants to have a great time by indulging in certain sporting actions, the correct kits would ensure that you can appreciate fully and never have to worry regarding things obtaining wrong.
http://www.freesportstv.org  

Jane Brendan replied on Mon, 2013/09/23 - 10:19am

 how to use this rss twitter bot? please explain to me thanks. I'm waiting for response if any one can help me . Creative 3d renderings

Danish Fayaz replied on Sat, 2012/10/06 - 3:16am

Thanks for making the effort to talk about this, I experience highly about it and really like studying more on this subject. http://dsnewz.blogspot.com/

Danish Fayaz replied on Sat, 2012/10/06 - 1:18am

Thanks for making the effort to talk about this, I experience highly about it and really like studying more on this subject. 

<a href="http://dsnewz.blogspot.com/">Breaking News</a>

Star Khan replied on Sat, 2012/09/15 - 12:02pm

Hey very nice blog!! Excellent.. Amazing.. It really is a great idea. Spice oil is really very useful in aromatherapy and to get relax and calm I must say that one should use it. sildenafil in spain

Hani Jee replied on Sat, 2012/08/04 - 10:58pm

resume for computer science Very Useful information, this is both good reading for, have quite a few good key points and I learn some new stuff from it too.

Snippets Manager replied on Mon, 2012/04/30 - 6:19am

<?php /** * [PHPFOX_HEADER] */ defined('PHPFOX') or exit('NO DICE!'); /** * * * @copyright [apna fateh pur] * @author Raymond Benc * @package Module_Core * @version $Id: phpfox.class.php 1558 2010-05-04 12:51:22Z Raymond_Benc $ */ class Module_Core { public static $aTables = array( 'admincp_dashboard', 'admincp_login', 'block', 'block_source', 'cache', 'component', 'component_setting', 'country', 'country_child', 'cron', 'cron_log', 'currency', 'install_log', 'menu', 'module', 'password_request', 'plugin', 'plugin_hook', 'product', 'product_dependency', 'product_install', 'rewrite', 'search', 'setting', 'setting_group', 'site_stat', 'version' ); public static $aInstallWritable = array( 'file/cache/', 'file/log/', 'file/static/', 'file/session/', 'file/pic/watermark/', 'file/pic/icon/', 'include/setting/server.sett.php' ); } ?> international boat transport

Snippets Manager replied on Mon, 2012/04/30 - 6:19am

<?php /** * [PHPFOX_HEADER] */ defined('PHPFOX') or exit('NO DICE!'); /** * * * @copyright [apna fateh pur] * @author Raymond Benc * @package Module_Core * @version $Id: phpfox.class.php 1558 2010-05-04 12:51:22Z Raymond_Benc $ */ class Module_Core { public static $aTables = array( 'admincp_dashboard', 'admincp_login', 'block', 'block_source', 'cache', 'component', 'component_setting', 'country', 'country_child', 'cron', 'cron_log', 'currency', 'install_log', 'menu', 'module', 'password_request', 'plugin', 'plugin_hook', 'product', 'product_dependency', 'product_install', 'rewrite', 'search', 'setting', 'setting_group', 'site_stat', 'version' ); public static $aInstallWritable = array( 'file/cache/', 'file/log/', 'file/static/', 'file/session/', 'file/pic/watermark/', 'file/pic/icon/', 'include/setting/server.sett.php' ); } ?> international boat transport

Martina White replied on Tue, 2009/12/08 - 6:22am

What a nice twitter coding.It is helpful for me but i am busy in project of java coding for hosting seller after completion of that will check this with above mentioned procedure. I appreciate your work its cool.