tjg-dresden: init

This commit is contained in:
Astro 2022-07-15 19:40:44 +02:00
parent 3e5bf57976
commit 09abca8232
2 changed files with 69 additions and 0 deletions

View File

@ -42,4 +42,5 @@ in {
hfmdd = wrapScript "hfmdd" ./hfmdd/scrape.rb;
hfbk-dresden = wrapScript "hfbk-dresden" ./hfbk-dresden/scrape.rb;
staatsoperette = wrapScript "staatsoperette" ./staatsoperette/scrape.rb;
tjg-dresden = wrapScript "tjg-dresden" ./tjg-dresden/scrape.rb;
}

68
tjg-dresden/scrape.rb Normal file
View File

@ -0,0 +1,68 @@
#!/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