@@ -21,7 +21,7 @@ require 'rexml/text'
21
21
require 'digest/md5'
22
22
23
23
OPTIONS = {
24
- :environment => "production " ,
24
+ :environment => "development " ,
25
25
# set this to 0 if you only want it to run once
26
26
# otherwise, set it to the number of seconds between polls
27
27
:wait_time => 0 ,
@@ -31,13 +31,13 @@ OPTIONS = {
31
31
32
32
ARGV . options do |opts |
33
33
opts . banner = "Usage: ruby #{ File . basename ( $0) } [options]"
34
-
34
+
35
35
opts . separator ''
36
-
36
+
37
37
opts . on ( '-e' , '--environment=name' , String ,
38
38
'Specifies the environment to run this server under (test/development/production).' ,
39
39
'Default: development' ) { |OPTIONS [ :environment ] | }
40
-
40
+
41
41
opts . on ( '-w' , '--wait-time=seconds' , Integer ,
42
42
'Specifies the number of seconds to wait between feed refreshes' ,
43
43
'Default: 300' ) { |OPTIONS [ :wait_time ] | }
@@ -54,62 +54,62 @@ quiet = OPTIONS[:quiet]
54
54
while ( true )
55
55
members = Member . find ( :all , "feed_url <> '' and feed_url is not null" )
56
56
STDOUT . puts "Beginning feed refresh for #{ members . size } Members..." unless quiet
57
-
57
+
58
58
members . each do |member |
59
59
begin
60
60
next unless member . feed_url =~ /\w +/
61
-
61
+
62
62
uri = URI . parse ( member . feed_url )
63
63
data = Net ::HTTP . get ( uri )
64
64
rss = SimpleRSS . parse ( data )
65
-
65
+
66
66
puts "Inspecting #{ rss . items . size } items for member #{ member . email } ..." unless quiet
67
-
67
+
68
68
update_count = 0
69
69
new_count = 0
70
-
70
+
71
71
seen = Hash . new
72
-
72
+
73
73
rss . items . each do |item |
74
74
# we care enough about the pubdate to skip items
75
75
# that dont have it
76
76
next if item . pubDate . nil?
77
-
77
+
78
78
content = unescape ( item . summary || item . content || item . description )
79
- hash = Digest ::MD5 . hexdigest ( content )
80
-
81
- # only look at the first one found (there should only be one)
82
- # since we "index" on the link, if a post is deleted, we would never know...
79
+ hash = Digest ::MD5 . hexdigest ( content )
80
+
81
+ # only look at the first one found (there should only be one)
82
+ # since we "index" on the link, if a post is deleted, we would never know...
83
83
found = Article . find ( :all , :conditions => [ 'member_id = ? and link = ?' , member . id , item . link ] ) . shift
84
84
85
- # note that we saw this item
86
- seen [ item . link ] = 1
87
-
88
- if !found . nil?
89
- # no change, nothing to see here
90
- next if found . content_hash == hash
91
-
92
- # update exisiting article
93
- found . title = unescape ( item . title )
94
- found . modified_at = item . pubDate
95
- found . content = content
96
- found . content_hash = hash
97
- found . save
98
-
99
- update_count += 1
100
- else
101
- # create a new article
102
- article = Article . new
85
+ # note that we saw this item
86
+ seen [ item . link ] = 1
87
+
88
+ if !found . nil?
89
+ # no change, nothing to see here
90
+ next if found . content_hash == hash
91
+
92
+ # update exisiting article
93
+ found . title = unescape ( item . title )
94
+ found . modified_at = item . pubDate
95
+ found . content = content
96
+ found . content_hash = hash
97
+ found . save
98
+
99
+ update_count += 1
100
+ else
101
+ # create a new article
102
+ article = Article . new
103
103
article . member = member
104
104
article . modified_at = ( item . pubDate )
105
105
article . title = unescape ( item . title )
106
106
article . link = item . link
107
- article . content = content
108
- article . content_hash = hash . to_s
107
+ article . content = content
108
+ article . content_hash = hash . to_s
109
109
article . save
110
110
111
- new_count += 1
112
- end
111
+ new_count += 1
112
+ end
113
113
114
114
end
115
115
@@ -119,9 +119,9 @@ while (true)
119
119
delete_count = 0
120
120
Article . find ( :all , :conditions => [ 'member_id = ?' , member . id ] ) . each { |a |
121
121
unless seen . has_key? a . link
122
- a . destroy
123
- delete_count += 1
124
- end
122
+ a . destroy
123
+ delete_count += 1
124
+ end
125
125
}
126
126
127
127
puts "Updated #{ update_count } items, created #{ new_count } new items, " +
@@ -131,7 +131,7 @@ while (true)
131
131
next
132
132
end
133
133
end
134
-
134
+
135
135
wait = OPTIONS [ :wait_time ]
136
136
if wait == 0
137
137
puts "Done." unless quiet
0 commit comments