Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit d989ada

Browse files
author
Lennon Day-Reynolds
committedAug 8, 2008
changed default environment for feeder script to match usage message
1 parent 687eeeb commit d989ada

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed
 

‎script/feeder

+41-41
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require 'rexml/text'
2121
require 'digest/md5'
2222

2323
OPTIONS = {
24-
:environment => "production",
24+
:environment => "development",
2525
# set this to 0 if you only want it to run once
2626
# otherwise, set it to the number of seconds between polls
2727
:wait_time => 0,
@@ -31,13 +31,13 @@ OPTIONS = {
3131

3232
ARGV.options do |opts|
3333
opts.banner = "Usage: ruby #{File.basename($0)} [options]"
34-
34+
3535
opts.separator ''
36-
36+
3737
opts.on('-e', '--environment=name', String,
3838
'Specifies the environment to run this server under (test/development/production).',
3939
'Default: development') { |OPTIONS[:environment]| }
40-
40+
4141
opts.on('-w', '--wait-time=seconds', Integer,
4242
'Specifies the number of seconds to wait between feed refreshes',
4343
'Default: 300') { |OPTIONS[:wait_time]| }
@@ -54,62 +54,62 @@ quiet = OPTIONS[:quiet]
5454
while (true)
5555
members = Member.find(:all, "feed_url <> '' and feed_url is not null")
5656
STDOUT.puts "Beginning feed refresh for #{members.size} Members..." unless quiet
57-
57+
5858
members.each do |member|
5959
begin
6060
next unless member.feed_url =~ /\w+/
61-
61+
6262
uri = URI.parse(member.feed_url)
6363
data = Net::HTTP.get(uri)
6464
rss = SimpleRSS.parse(data)
65-
65+
6666
puts "Inspecting #{rss.items.size} items for member #{member.email}..." unless quiet
67-
67+
6868
update_count = 0
6969
new_count = 0
70-
70+
7171
seen = Hash.new
72-
72+
7373
rss.items.each do |item|
7474
# we care enough about the pubdate to skip items
7575
# that dont have it
7676
next if item.pubDate.nil?
77-
77+
7878
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...
8383
found = Article.find(:all, :conditions => ['member_id = ? and link = ?',member.id,item.link]).shift
8484

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
103103
article.member = member
104104
article.modified_at = (item.pubDate)
105105
article.title = unescape(item.title)
106106
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
109109
article.save
110110

111-
new_count += 1
112-
end
111+
new_count += 1
112+
end
113113

114114
end
115115

@@ -119,9 +119,9 @@ while (true)
119119
delete_count = 0
120120
Article.find(:all, :conditions => ['member_id = ?',member.id]).each{ |a|
121121
unless seen.has_key? a.link
122-
a.destroy
123-
delete_count += 1
124-
end
122+
a.destroy
123+
delete_count += 1
124+
end
125125
}
126126

127127
puts "Updated #{update_count} items, created #{new_count} new items, " +
@@ -131,7 +131,7 @@ while (true)
131131
next
132132
end
133133
end
134-
134+
135135
wait = OPTIONS[:wait_time]
136136
if wait == 0
137137
puts "Done." unless quiet

0 commit comments

Comments
 (0)
This repository has been archived.