63 lines
1.3 KiB
Ruby
63 lines
1.3 KiB
Ruby
#!/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 "<html><body>#{result['content']}</body></html>"
|
|
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
|