diff --git a/default.nix b/default.nix index aa19fac..49acb8d 100644 --- a/default.nix +++ b/default.nix @@ -39,4 +39,5 @@ in { dresden-versammlungen = wrapScript "dresden-versammlungen" ./dresden-versammlungen/scrape.rb; azconni = wrapScript "azconni" ./azconni/scrape.rb; kunsthaus = wrapScript "kunsthaus" ./kunsthaus/scrape.rb; + hfmdd = wrapScript "hfmdd" ./hfmdd/scrape.rb; } diff --git a/hfmdd/scrape.rb b/hfmdd/scrape.rb new file mode 100644 index 0000000..ea6e960 --- /dev/null +++ b/hfmdd/scrape.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby +# coding: utf-8 + +require 'open-uri' +require 'json' +require 'nokogiri' +require 'erb' + +events = [] + +url = "https://www.hfmdd.de/?type=1341&tx_dtmevents_dtmevents%5Baction%5D=getDtmEvents&tx_dtmevents_dtmevents%5Bcontroller%5D=Event&L=0&tx_dtmevents_dtmevents%5Bview%5D=a-z&tx_dtmevents_dtmevents%5Beventtypes%5D=" +STDERR.puts "GET #{url}" +result = JSON::parse URI.open(url).read +if result['action'] != "OK" + throw "action is #{result['action'].inspect}" +end + +doc = Nokogiri::HTML "#{result['content']}" +doc.css("a.link_ics").each do |a| + link = URI.join url, a.attr('href') + event_line = false + has_url = false + STDERR.puts "GET #{link}" + ical = URI.open(link).read + events.push ical.lines.collect { |line| + case line.chomp + when "BEGIN:VEVENT" + event_line = true + line + when "END:VEVENT" + event_line = false + if has_url + line + else + url = link.to_s.sub(/\?.*/, "") + ["URL:#{url}\n", line] + end + when /URL:/ + if event_line + has_url = true + line + else + [] + end + else + event_line ? line : [] + end + }.flatten.join +end + +ical = ERB::new <<~EOF + BEGIN:VCALENDAR + VERSION:2.0 + METHOD:PUBLISH + X-WR-TIMEZONE;VALUE=TEXT:Europe/Berlin + + <%= events.join "\n" %> + + END:VCALENDAR +EOF + +puts ical.result