Skip to content

Instantly share code, notes, and snippets.

@reima
Created June 10, 2009 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reima/127087 to your computer and use it in GitHub Desktop.
Save reima/127087 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rss/maker'
require 'nokogiri'
require 'open-uri'
URL = 'http://wwwrbg.in.tum.de/kontakt/FMI_Bistro/aktuell.html'
DAY_PATTERN = /\d?\d\.\d?\d.\d{4}/
MEAL_PATTERN = /(\d+)\.((?:.|\n)+?\d\.\d\d)$/
DATES = {
Date.today.strftime("%-1d.%-1m.%Y") => "Heute",
(Date.today + 1).strftime("%d.%-1m.%Y") => "Morgen",
}
feed = RSS::Maker.make('2.0') do |rss|
doc = Nokogiri::HTML(open(URL))
rss.channel.title = (doc/'title').text
rss.channel.description = rss.channel.title
rss.channel.link = URL
rss.channel.lastBuildDate = Time.now
rss.encoding = 'iso-8859-1'
text = (doc/'.maincontent').text
text.scan(/(#{DAY_PATTERN})$((\s*#{MEAL_PATTERN})+)/) do |day, meals|
dayname = DATES[day] or next
meals.scan(MEAL_PATTERN).map do |meal|
meal[1] = meal[1].
gsub(/\b[VKRS+]+\s/, '').
gsub(/(\b| )\d(?=,| )(,\d)*/, '').
gsub(/\*{1,3}/, '').
gsub(/\s+/, ' ')
rss.items.new_item do |item|
item.title = "#{dayname} - #{meal[0]}. #{meal[1]}"
item.link = URL
item.guid.content = URL + "#" + day + "-" + meal[0]
end
end
end
end
puts feed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment