Sha256: 999de817f47236af05bdae39b0bd177dc4984c9b5bb3b8aa3bb9272cf3de2aa7
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
require 'rss/1.0' require 'rss/2.0' require 'open-uri' class RSS2WikiHelper DEFAULT_SETTINGS = { :url => 'http://localhost:8000/rss/recent%20changes%20to%20this%20site', :pagename => nil, # If nil, uses channel title, :check_frequency => 1200, :author => 'AutomaticRSS2Wiki', } def initialize( wiki, settings = {} ) @settings = DEFAULT_SETTINGS.merge( settings ) @wiki = wiki Thread.new do loop do update_rss update_wiki sleep @settings[ :check_frequency ] end end end def update_wiki @wiki.revise( @settings[:pagename] || @rss.channel.title, render, @rss.items.first.respond_to?('author') ? @rss.items.first.author : "AutomaticRSS" ) end def render content = "h1. #{@rss.channel.title}\n\n" @rss.items.each do |item| content << "# [[ #{escape(item.title)} => #{item.link} ]]\n" end content end def update_rss $stderr.puts "Updating feed" open(@settings[:url]) do |http| @rss = RSS::Parser.parse( http.read , false) end end def escape( string ) string.tr('[]=>','') end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
Soks-0.0.5 | lib/helpers/rss2wiki-helper.rb |
Soks-0.0.6 | lib/helpers/rss2wiki-helper.rb |
Soks-0.0.7 | lib/helpers/rss2wiki-helper.rb |