Created
September 23, 2010 17:15
-
-
Save southly/594001 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 02f18b9ed7f6fed148f75d601905d07ad1d23297 Mon Sep 17 00:00:00 2001 | |
From: NANRI <[email protected]> | |
Date: Thu, 23 Sep 2010 21:53:38 +0900 | |
Subject: [PATCH 1/3] add generate_rss. | |
--- | |
main.rb | 34 ++++++++++++++++++++++++++++++++++ | |
1 files changed, 34 insertions(+), 0 deletions(-) | |
diff --git a/main.rb b/main.rb | |
index ad6f1d5..b183e6f 100755 | |
--- a/main.rb | |
+++ b/main.rb | |
@@ -36,6 +36,7 @@ require 'htree' | |
require 'string-util' | |
require 'tempfile' | |
require 'presen' | |
+require "rss" | |
CONFIG_FILENAME = 'config.yml' | |
STATUS_FILENAME = 'status.rm' | |
@@ -43,6 +44,12 @@ STATUS_FILENAME = 'status.rm' | |
TEMPLATE_LATEST_FILENAME = 't.latest.html' | |
OUTPUT_LATEST_FILENAME = 'latest.html' | |
OUTPUT_LIRS_FILENAME = 'sites.lirs.gz' | |
+OUTPUT_RSS_FILENAME = 'index.rdf' | |
+ | |
+RSS_ABOUT = 'http://example.com/index.rdf' | |
+RSS_TITLE = 'Example' | |
+RSS_DESCRIPTION = 'Example Site' | |
+RSS_LINK = 'http://example.com/' | |
AutoFile.directory = 'tmp' # xxx: should be configurable. | |
@@ -1258,9 +1265,30 @@ class Samidare | |
output_file(@opt_output_lirs, str) | |
end | |
+ def generate_rss(data) | |
+ rss = RSS::Maker.make("1.0") do |maker| | |
+ maker.channel.about = RSS_ABOUT | |
+ maker.channel.title = RSS_TITLE | |
+ maker.channel.description = RSS_DESCRIPTION | |
+ maker.channel.link = RSS_LINK | |
+ | |
+ data["antenna"].sort_by {|e| - e['last-modified'].to_i }.first(30).each {|h| | |
+ next unless h['last-modified'] && h['last-modified-found'] | |
+ | |
+ item = maker.items.new_item | |
+ item.link = h['linkURI'] | |
+ item.title = h['title'] | |
+ item.date = h['last-modified'] | |
+ } | |
+ end | |
+ | |
+ output_file(@opt_output_rss, rss.to_s) | |
+ end | |
+ | |
def parse_options | |
@opt_output = OUTPUT_LATEST_FILENAME | |
@opt_output_lirs = OUTPUT_LIRS_FILENAME | |
+ @opt_output_rss = OUTPUT_RSS_FILENAME | |
@opt_dont_check = nil | |
@opt_force_check = nil | |
@opt_timing = nil | |
@@ -1280,6 +1308,7 @@ class Samidare | |
q.def_option('--force', '-f', 'force check (avoid timing control mechanism)') { @opt_force_check = true } | |
q.def_option('--output=filename', '-o', 'specify output html file') {|filename| @opt_output = filename } | |
q.def_option('--output-lirs=filename', 'specify output lirs file') {|filename| @opt_output_lirs = filename } | |
+ q.def_option('--output-rss=filename', 'specify output rss file') {|filename| @opt_output_rss = filename } | |
q.def_option('--template=filename', '-T', 'specify template') {|filename| @opt_template = filename } | |
q.def_option('--timing', '-t', 'show timings') { @opt_timing = true } | |
q.def_option('--dump-config', 'dump flatten configuration') { @opt_dump_config = true } | |
@@ -1472,6 +1501,11 @@ class Samidare | |
generate_lirs(data) | |
t2 = Time.now | |
STDERR.puts " #{(t2-t1).to_f}sec" if $VERBOSE | |
+ STDERR.print "generating rss..." if $VERBOSE | |
+ t1 = Time.now | |
+ generate_rss(data) | |
+ t2 = Time.now | |
+ STDERR.puts " #{(t2-t1).to_f}sec" if $VERBOSE | |
end | |
} | |
#PP.pp(data, STDERR) if $VERBOSE | |
-- | |
1.7.2.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment