#!/usr/bin/env ruby # coding: utf-8 require 'open-uri' require 'csv' require 'time' require 'erb' def fmt_time t t.strftime "%Y%m%dT%H%M%S" end class Event attr_accessor :title, :link attr_reader :dtstart, :dtend, :location def location=(s) @location = "#{s}, theater junge generation" end def date=(s) @dtstart = Time::parse s @dtend = @dtstart + 7200 end end events = [] url = "https://www.tjg-dresden.de/eventexport/csv.html" body = URI.open(url).read.force_encoding 'UTF-8' events = CSV::parse(body, headers: true, col_sep: ";").collect do |row| ev = Event::new row.each do |k, v| case k when /Titel/ ev.title = v when /Ort/ ev.location = v when /Link/ ev.link = v when /Datum/ ev.date = v end end ev 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.link %> URL:<%= ev.link %> LOCATION:<%= ev.location %> END:VEVENT <% end %> END:VCALENDAR EOF puts ical.result