public
Description: Read an RSS feed (even HTTPS with authentication) and rebroadcast it to a Twitter account.
Clone URL: git://github.com/trak3r/rss2twitter.git
Search Repo:
trak3r (author)
Wed Apr 30 07:07:04 -0700 2008
commit  149c7f9389a7c6d10d589d81409532f7f1212a10
tree    ff8d54d85e0b077ff068d6c2da8915d18ec43a78
parent  48eef21d8beec7ff101790ea83422f6a612b688b
rss2twitter / database.rb
100644 49 lines (38 sloc) 1.138 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'active_record'
require 'shorturl'
 
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
 
ActiveRecord::Base.establish_connection(
    :adapter => "sqlite3",
    :dbfile => 'rss2twitter.db'
)
 
class Item < ActiveRecord::Base
 
  def to_s
    "#{self.optimized_title[0..(tweet_limit-self.short_url.length)]} #{self.short_url}"
  end
  
  protected
  
  def tweet_limit
    138 # leave one off for fudging
  end
 
  def short_url
    @cached_short_url ||= ShortURL.shorten(self.link, :metamark)
  end
  
  def optimized_title
    # for Trac feeds (which is why I wrote this) strip off some
    # extraneous verbiage to save every last precious character
    tidbits = self.title.scan( /^Changeset \[(.*?)\]\: (.*)/ ).flatten
    if 2 == tidbits.length
      return tidbits[1] # sprintf( "%s %s", *tidbits )
    else # not a Trac changeset or we failed to parse it
      return self.title
    end
  end
 
end
 
unless Item.table_exists?
  ActiveRecord::Schema.define do
    create_table :items do |table|
        table.column :title, :string
        table.column :link, :string
    end
  end
end