kreuzchor-termine: init

This commit is contained in:
Astro 2021-09-06 01:26:50 +02:00
parent 16962f087f
commit a625635ee1
2 changed files with 58 additions and 0 deletions

View File

@ -31,4 +31,5 @@ in {
freifunk_node = wrapScript "freifunk_node" ./freifunk_node/scrape.rb;
impfee = wrapScript "impfee" ./impfee/scrape.rb;
riesa-efau-kalender = wrapScript "riesa-efau-kalender" ./riesa-efau-kalender/scrape.rb;
kreuzchor-termine = wrapScript "kreuzchor-termine" ./kreuzchor-termine/scrape.rb;
}

View File

@ -0,0 +1,57 @@
#!/usr/bin/env ruby
# coding: utf-8
require 'open-uri'
require 'json'
require 'erb'
def fmt_time t
t.strftime "%Y%m%dT%H%M%S"
end
class Event
attr_accessor :name, :location, :link, :date
end
events = []
url = "https://kreuzchor.de/termine-tickets/"
data = URI.open(url).read()
if data =~ /var php_vars = (\{.+\});$/
json = JSON.parse $1
else
raise "Data not found"
end
json['events'].each do |event|
ev = Event::new
ev.name = event['title']
ev.location = event['venue']
ev.date = Time.at(event['event_time'] / 1000, in: 0)
ev.link = event['permalink'].empty? ? event['event_link'] : event['permalink']
events << ev
end
events.sort_by! { |ev| ev.date }
ical = ERB::new <<~EOF
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
X-WR-TIMEZONE;VALUE=TEXT:Europe/Berlin
<% events.each do |ev| %>
BEGIN:VEVENT
METHOD:PUBLISH
CLASS:PUBLIC
UID:<%= ev.link %>
DTSTART:<%= fmt_time(ev.date) %>
DTEND:<%= fmt_time(ev.date + 2 * 3600) %>
SUMMARY:<%= ev.name %>
LOCATION:<%= ev.location %>
URL:<%= ev.link %>
END:VEVENT
<% end %>
END:VCALENDAR
EOF
puts ical.result