Report abuse

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
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby

require 'rubygems'
require 'erb'
require 'feed_tools'

load 'lib/sqlite3_feed_cache.rb'

# load config
config = YAML::load(File.open('config/config.yml'))

# set up caching
SQLite3FeedCache.set_db('db/feeds.db')
FeedTools::configurations[:feed_cache] = SQLite3FeedCache
puts "Warning: requests are NOT cached!" unless FeedTools::feed_cache_connected?

# get feeds
unparsed_feeds = YAML::load(File.open('config/feeds.yml'))

# parse feeds feeds
puts 'Parsing feeds.'
feeds = []
unparsed_feeds.each do |feed|
  puts "  Parsing #{feed['url']}."
  begin
    feeds << FeedTools::Feed.open(feed['url'])
  rescue
    puts '    !!! error'
  end
end

# get entries
# !!!!! SLOW !!!!!
puts 'Getting entries.'
entries = []
feeds.each do |feed|
  feed.entries.each do |entry|
    entries << entry
  end
end

# sort entries
# !!!!! SLOW !!!!!
puts 'Sorting entries.'
entries.sort! { |a,b| a.published <=> b.published }

# ignore old entries
entries = entries.first(20)

# erbize
puts 'Writing output.'
config['templates'].each do |template|
  puts "  Writing #{template.gsub(/\.rhtml$/, '')} template."
  path = config['output_directory'] + '/' + template.gsub(/\.rhtml$/, '.html')
  out = File.open(path, 'w')
  erb = ERB.new(File.read('templates/' + template))
  out.print(erb.result(binding))
end

puts 'Done.'