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
|
# File 'lib/nutritious.rb', line 9
def self.process_single_bookmark(e)
entry_id = $1 if e.entry_id =~ /.*url\/(.+)#/
all_tags = Hash.new(0)
e.categories.each { |cat| all_tags[cat] += 1 }
detailed_feed = Feedzirra::Feed.fetch_and_parse("http://feeds.delicious.com/v2/rss/url/#{entry_id}?count=20")
detailed_feed.entries.each { |p| p.categories.each { |cat| all_tags[cat] += 1 } }
consensus_tags = all_tags.to_a.sort{ |a,b| a[1] <=> b[1]}.reverse.slice(0,5).reject { |t| t[1]<3 }
if consensus_tags.empty?
return nil
end
doc = open(e.url) { |f| Hpricot(f) }
doc.search("script").remove
doc.search("style").remove
body = doc.search("body").text.gsub(/\s+/, ' ')
{:url => e.url, :title =>e.title, :tags => consensus_tags.map { |t| t[0] }, :body => body}
rescue
nil
end
|