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:
Organized mess of files into directory structure.
trak3r (author)
Wed Apr 30 07:14:47 -0700 2008
commit  6b14da44c08cead2081816d3555ac84cf786f3ed
tree    d111e13de617d71a1baaafb2c4d5eabae4247f5b
parent  149c7f9389a7c6d10d589d81409532f7f1212a10
...
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,47 +1 @@
0
-require 'yaml'
0
-
0
-class Settings
0
-
0
- attr_reader :rss_url, :twitter_email, :twitter_password
0
-
0
- def initialize
0
- begin
0
- prefs = YAML::load_file("#{@@yaml_file_name}")
0
- rescue
0
- missing_or_empty_yaml
0
- end
0
-
0
- missing_or_empty_yaml unless prefs
0
-
0
- @twitter_email = yamlized(prefs,'twitter_email')
0
- @twitter_password = yamlized(prefs,'twitter_password')
0
- @rss_url = yamlized(prefs,'rss_url')
0
- end
0
-
0
- private
0
-
0
- @@yaml_file_name = 'rss2twitter.yml'
0
-
0
- def missing_or_empty_yaml
0
- print <<"EOF"
0
-
0
- Please define a YAML file named #{@@yaml_file_name}
0
- containing the following values:
0
-
0
- twitter_email: 'yourtwitteremail@bla.com'
0
- twitter_password: 'secret'
0
- rss_url: 'https://username:password@yoursite.com/index.xml'
0
-
0
-EOF
0
- exit
0
- end
0
-
0
- def yamlized(prefs,token)
0
- if prefs["#{token}"]
0
- return prefs["#{token}"]
0
- else
0
- raise "Please define \"#{token}\" in your YAML file."
0
- end
0
- end
0
-end
...
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,49 +1 @@
0
-require 'active_record'
0
-require 'shorturl'
0
-
0
-ActiveRecord::Base.logger = Logger.new(STDERR)
0
-ActiveRecord::Base.colorize_logging = false
0
-
0
-ActiveRecord::Base.establish_connection(
0
- :adapter => "sqlite3",
0
- :dbfile => 'rss2twitter.db'
0
-)
0
-
0
-class Item < ActiveRecord::Base
0
-
0
- def to_s
0
- "#{self.optimized_title[0..(tweet_limit-self.short_url.length)]} #{self.short_url}"
0
- end
0
-
0
- protected
0
-
0
- def tweet_limit
0
- 138 # leave one off for fudging
0
- end
0
-
0
- def short_url
0
- @cached_short_url ||= ShortURL.shorten(self.link, :metamark)
0
- end
0
-
0
- def optimized_title
0
- # for Trac feeds (which is why I wrote this) strip off some
0
- # extraneous verbiage to save every last precious character
0
- tidbits = self.title.scan( /^Changeset \[(.*?)\]\: (.*)/ ).flatten
0
- if 2 == tidbits.length
0
- return tidbits[1] # sprintf( "%s %s", *tidbits )
0
- else # not a Trac changeset or we failed to parse it
0
- return self.title
0
- end
0
- end
0
-
0
-end
0
-
0
-unless Item.table_exists?
0
- ActiveRecord::Schema.define do
0
- create_table :items do |table|
0
- table.column :title, :string
0
- table.column :link, :string
0
- end
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,16 +1 @@
0
-require 'net/http'
0
-require 'net/https'
0
-require 'open-uri'
0
-require 'simple-rss'
0
-
0
-def process(rss_url)
0
- parsed_uri = URI.parse(rss_url)
0
- http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
0
- http.use_ssl = 'https' == parsed_uri.scheme
0
- request = Net::HTTP::Get.new("#{parsed_uri.path}?#{parsed_uri.query}")
0
- request.basic_auth parsed_uri.user, parsed_uri.password
0
- response = http.request(request)
0
- rss_items = SimpleRSS.parse response.body
0
- return rss_items.items.reverse
0
-end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,47 @@
0
+require 'yaml'
0
+
0
+class Settings
0
+
0
+ attr_reader :rss_url, :twitter_email, :twitter_password
0
+
0
+ def initialize
0
+ begin
0
+ prefs = YAML::load_file("#{@@yaml_file_name}")
0
+ rescue
0
+ missing_or_empty_yaml
0
+ end
0
+
0
+ missing_or_empty_yaml unless prefs
0
+
0
+ @twitter_email = yamlized(prefs,'twitter_email')
0
+ @twitter_password = yamlized(prefs,'twitter_password')
0
+ @rss_url = yamlized(prefs,'rss_url')
0
+ end
0
+
0
+ private
0
+
0
+ @@yaml_file_name = 'rss2twitter.yml'
0
+
0
+ def missing_or_empty_yaml
0
+ print <<"EOF"
0
+
0
+ Please define a YAML file named #{@@yaml_file_name}
0
+ containing the following values:
0
+
0
+ twitter_email: 'yourtwitteremail@bla.com'
0
+ twitter_password: 'secret'
0
+ rss_url: 'https://username:password@yoursite.com/index.xml'
0
+
0
+EOF
0
+ exit
0
+ end
0
+
0
+ def yamlized(prefs,token)
0
+ if prefs["#{token}"]
0
+ return prefs["#{token}"]
0
+ else
0
+ raise "Please define \"#{token}\" in your YAML file."
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,49 @@
0
+require 'active_record'
0
+require 'shorturl'
0
+
0
+ActiveRecord::Base.logger = Logger.new(STDERR)
0
+ActiveRecord::Base.colorize_logging = false
0
+
0
+ActiveRecord::Base.establish_connection(
0
+ :adapter => "sqlite3",
0
+ :dbfile => 'rss2twitter.db'
0
+)
0
+
0
+class Item < ActiveRecord::Base
0
+
0
+ def to_s
0
+ "#{self.optimized_title[0..(tweet_limit-self.short_url.length)]} #{self.short_url}"
0
+ end
0
+
0
+ protected
0
+
0
+ def tweet_limit
0
+ 138 # leave one off for fudging
0
+ end
0
+
0
+ def short_url
0
+ @cached_short_url ||= ShortURL.shorten(self.link, :metamark)
0
+ end
0
+
0
+ def optimized_title
0
+ # for Trac feeds (which is why I wrote this) strip off some
0
+ # extraneous verbiage to save every last precious character
0
+ tidbits = self.title.scan( /^Changeset \[(.*?)\]\: (.*)/ ).flatten
0
+ if 2 == tidbits.length
0
+ return tidbits[1] # sprintf( "%s %s", *tidbits )
0
+ else # not a Trac changeset or we failed to parse it
0
+ return self.title
0
+ end
0
+ end
0
+
0
+end
0
+
0
+unless Item.table_exists?
0
+ ActiveRecord::Schema.define do
0
+ create_table :items do |table|
0
+ table.column :title, :string
0
+ table.column :link, :string
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1 +1,16 @@
0
+require 'net/http'
0
+require 'net/https'
0
+require 'open-uri'
0
+require 'simple-rss'
0
+
0
+def process(rss_url)
0
+ parsed_uri = URI.parse(rss_url)
0
+ http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
0
+ http.use_ssl = 'https' == parsed_uri.scheme
0
+ request = Net::HTTP::Get.new("#{parsed_uri.path}?#{parsed_uri.query}")
0
+ request.basic_auth parsed_uri.user, parsed_uri.password
0
+ response = http.request(request)
0
+ rss_items = SimpleRSS.parse response.body
0
+ return rss_items.items.reverse
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1 +1,21 @@
0
+require 'rubygems'
0
+require 'twitter'
0
+
0
+require 'config'
0
+require 'database'
0
+require 'feed'
0
+
0
+def parse_and_push
0
+ settings = Settings.new
0
+
0
+ for item in process(settings.rss_url)
0
+ Item.transaction do
0
+ unless existing_item = Item.find(:all, :conditions => ["link=?", item.link]).first
0
+ twitter ||= Twitter::Base.new(settings.twitter_email, settings.twitter_password)
0
+ new_item = Item.create(:title => item.title, :link => item.link)
0
+ twitter.post(new_item.to_s)
0
+ end
0
+ end
0
+ end
0
+end
...
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,34 +1 @@
0
-#!/bin/ruby
0
-
0
-require 'rubygems'
0
-require 'shorturl'
0
-
0
-[ 'rubyurl',
0
- 'tinyurl',
0
- 'shorl',
0
- 'snipurl',
0
- 'metamark',
0
- 'makeashorterlink',
0
- 'skinnylink',
0
- 'linktrim',
0
- 'shorterlink',
0
- 'minlink',
0
- 'lns',
0
- 'fyad',
0
- 'd62',
0
- 'shiturl',
0
- 'littlink',
0
- 'clipurl',
0
- 'shortify',
0
- 'orz',
0
- 'moourl',
0
- 'urltea'].each do |method|
0
- printf "%20s: ", method
0
- begin
0
- printf "%s", ShortURL.shorten('http://trak3r.blogspot.com', method.to_sym)
0
- rescue InvalidService, SocketError
0
- printf "broken!"
0
- end
0
- printf "\n"
0
-end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,34 @@
0
+#!/bin/ruby
0
+
0
+require 'rubygems'
0
+require 'shorturl'
0
+
0
+[ 'rubyurl',
0
+ 'tinyurl',
0
+ 'shorl',
0
+ 'snipurl',
0
+ 'metamark',
0
+ 'makeashorterlink',
0
+ 'skinnylink',
0
+ 'linktrim',
0
+ 'shorterlink',
0
+ 'minlink',
0
+ 'lns',
0
+ 'fyad',
0
+ 'd62',
0
+ 'shiturl',
0
+ 'littlink',
0
+ 'clipurl',
0
+ 'shortify',
0
+ 'orz',
0
+ 'moourl',
0
+ 'urltea'].each do |method|
0
+ printf "%20s: ", method
0
+ begin
0
+ printf "%s", ShortURL.shorten('http://trak3r.blogspot.com', method.to_sym)
0
+ rescue InvalidService, SocketError
0
+ printf "broken!"
0
+ end
0
+ printf "\n"
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1 +1,12 @@
0
+#!/bin/ruby
0
+
0
+max = 140 # message limit for twitter
0
+
0
+for x in 1..max do
0
+ printf "%d", ( x % 10 )
0
+end
0
+printf "\n"
0
+
0
+msg = "You are only coming through in waves. Your lips move but I can't hear what you're saying. I have become comfortably numb. A distant ship's smoke on the horizon."
0
+printf "%s", msg[0..max]
...
1
2
3
4
5
6
7
8
9
10
11
...
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,12 +1 @@
0
-#!/bin/ruby
0
-
0
-max = 140 # message limit for twitter
0
-
0
-for x in 1..max do
0
- printf "%d", ( x % 10 )
0
-end
0
-printf "\n"
0
-
0
-msg = "You are only coming through in waves. Your lips move but I can't hear what you're saying. I have become comfortably numb. A distant ship's smoke on the horizon."
0
-printf "%s", msg[0..max]
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,21 +1 @@
0
-require 'rubygems'
0
-require 'twitter'
0
-
0
-require 'config'
0
-require 'database'
0
-require 'feed'
0
-
0
-def parse_and_push
0
- settings = Settings.new
0
-
0
- for item in process(settings.rss_url)
0
- Item.transaction do
0
- unless existing_item = Item.find(:all, :conditions => ["link=?", item.link]).first
0
- twitter ||= Twitter::Base.new(settings.twitter_email, settings.twitter_password)
0
- new_item = Item.create(:title => item.title, :link => item.link)
0
- twitter.post(new_item.to_s)
0
- end
0
- end
0
- end
0
-end

Comments

    No one has commented yet.