64 lines
1.1 KiB
Ruby
64 lines
1.1 KiB
Ruby
|
#!/usr/bin/env ruby
|
||
|
# coding: utf-8
|
||
|
|
||
|
require 'open-uri'
|
||
|
require 'time'
|
||
|
require 'nokogiri'
|
||
|
require 'erb'
|
||
|
|
||
|
def fmt_time t
|
||
|
t.strftime "%Y%m%dT%H%M%S"
|
||
|
end
|
||
|
|
||
|
class Event
|
||
|
attr_accessor :title, :url
|
||
|
attr_reader :date, :location, :dtstart
|
||
|
|
||
|
def initialize
|
||
|
@location = "Hochschule für Bildende Künste Dresden"
|
||
|
end
|
||
|
|
||
|
def dtend
|
||
|
@dtstart + 7200
|
||
|
end
|
||
|
|
||
|
def date=(s)
|
||
|
@dtstart = Time::parse(s)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
events = []
|
||
|
|
||
|
url = "https://www.hfbk-dresden.de/veranstaltungen"
|
||
|
doc = Nokogiri::HTML URI.open(url)
|
||
|
doc.css(".topnews").each do |content|
|
||
|
time = content.css("time").attr("datetime").text
|
||
|
title_link = content.css("h3 a")
|
||
|
|
||
|
ev = Event::new
|
||
|
ev.title = title_link.attr("title").text
|
||
|
ev.url = URI.join url, title_link.attr("href")
|
||
|
ev.date = time
|
||
|
events << 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.url %>
|
||
|
URL:<%= ev.url %>
|
||
|
LOCATION:<%= ev.location %>
|
||
|
END:VEVENT
|
||
|
<% end %>
|
||
|
END:VCALENDAR
|
||
|
EOF
|
||
|
|
||
|
puts ical.result
|