#!/usr/bin/env ruby # coding: utf-8 require 'open-uri' require 'nokogiri' require 'erb' require 'time' def fmt_time t t.strftime "%Y%m%dT%H%M%S" end class Event attr_accessor :title, :url attr_reader :dtstart, :dtend def initialize @location = "Hygienemuseum" end def date=(t) @dtstart = t @dtend = @dtstart + 3600 end end events = [] url = "http://kosmotique.org/feed.xml" doc = Nokogiri::HTML URI.open(url) doc.css("entry").each do |entry| begin ev = Event::new ev.title = entry.css("title").text ev.url = entry.css("link").attr "href" ev.date = Time.parse entry.css("published").text events << ev rescue STDERR.puts "Omitting: #{$!}" STDERR.puts $!.backtrace end end ical = ERB::new <<~EOF BEGIN:VCALENDAR VERSION:2.0 METHOD:PUBLISH X-WR-TIMEZONE;VALUE=TEXT:Europe/Berlin <% events.each do |ev| %> BEGIN:VEVENT SUMMARY:<%= ev.title %> DTSTART:<%= fmt_time ev.dtstart %> DTEND:<%= fmt_time ev.dtend %> UID:<%= ev.url %> URL:<%= ev.url %> LOCATION:Kosmotique, Martin-Luther-Str. 13, Dresden END:VEVENT <% end %> END:VCALENDAR EOF puts ical.result