Skip to content

Commit

Permalink
working on feed to text
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Choi committed Feb 18, 2011
1 parent 23f1071 commit 9411eae
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ gmail.yml
pkg/
.rvmrc
notes.txt
.bundle
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,3 +1,3 @@
source :rubygems
gem 'nokogiri'
gem 'feed_yamlizer'
gem 'feed_yamlizer', '>= 0.0.3'
19 changes: 19 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,19 @@
GEM
remote: http://rubygems.org/
specs:
feed_yamlizer (0.0.2)
htmlentities
nokogiri
sqlite3-ruby
htmlentities (4.2.4)
nokogiri (1.4.4)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)

PLATFORMS
ruby

DEPENDENCIES
feed_yamlizer
nokogiri
59 changes: 38 additions & 21 deletions lib/vnews/aggregator.rb
Expand Up @@ -7,16 +7,18 @@
class Vnews
class Aggregator
include Autodiscoverer
def initialize(config={})

def initialize(out=nil)
@out = out
end

def get_feed(feed_url)
feed_url = repair feed_url
response = open(feed_url)
xml = response.read
# puts response.last_modified
puts response.content_type
puts response.charset
$stderr.puts response.content_type
$stderr.puts response.charset
charset = response.charset || "ISO-8859-1"

if response.content_type !~ /xml/
Expand All @@ -28,28 +30,46 @@ def get_feed(feed_url)
nil
end
end
puts "Running"
$stderr.puts "Running"
feed_yaml = FeedYamlizer.run(xml, charset)
end

# input is a hash
def print_feed(url)
f = get_feed url
f[:items].each {|i|
puts '-' * 80
puts i[:title]
puts
def munge_title(title)
title.gsub(/\W/, '-') + '.txt'
end

# f is a hash; get from get_feed()
def feed_to_s(f)
out = []
f[:meta].each {|k, v| out << "# #{v}" }
out << ''
f[:items].each do |i|
out << '-' * 10
out << ''
out << i[:title]
out << ''
header = []
header << i[:link]
header << i[:pub_date].strftime("%b %d")
if i[:author]
header << "By #{i[:author]}"
end
puts header.map {|x| " " + x.to_s}.join("\n\n")
puts
puts i[:content][:text].strip.gsub(/^/, " ") # indent body 4 spaces
puts
}
out << header.map {|x| " " + x.to_s}.join("\n\n")
out << ''
out << i[:content][:text].strip.gsub(/^/, " ") # indent body 4 spaces
out << ''
out << " #{i[:link]}"
out << ''
end
out.join("\n")
end

# input is a hash
def print_feed(url)
f = get_feed url
file = @out || munge_title(f[:meta][:title])
File.open(file, 'w') do |out|
out.puts feed_to_s(f)
end
end

def import_opml(opml)
Expand All @@ -70,11 +90,8 @@ def repair(feed_url)
end

def log(text)
$stderr.puts text
stderr.puts text
end



end
end

Expand Down

0 comments on commit 9411eae

Please sign in to comment.