hfmdd: init

This commit is contained in:
Astro 2022-07-15 01:08:11 +02:00
parent adfe2a4feb
commit 20011c4f20
2 changed files with 63 additions and 0 deletions

View File

@ -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;
}

62
hfmdd/scrape.rb Normal file
View File

@ -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 "<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