kosmotique: add

This commit is contained in:
Astro 2023-01-12 20:52:45 +01:00
parent eef1310cd8
commit 8e5e23360f
2 changed files with 62 additions and 0 deletions

View File

@ -47,4 +47,5 @@ in {
nabu = wrapScript "nabu" ./nabu/scrape.rb;
museen-dresden = wrapScript "museen-dresden" ./museen-dresden/scrape.rb;
criticalmass = wrapScript "criticalmass" ./criticalmass/scrape.rb;
kosmotique = wrapScript "kosmotique" ./kosmotique/scrape.rb;
}

61
kosmotique/scrape.rb Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env ruby
# coding: utf-8
require 'open-uri'
require 'nokogiri'
require 'erb'
require 'time'
def fmt_time t
t.strftime "%Y%m%dT%H%M%S"
end
class Event
attr_accessor :title, :url
attr_reader :dtstart, :dtend
def initialize
@location = "Hygienemuseum"
end
def date=(t)
@dtstart = t
@dtend = @dtstart + 3600
end
end
events = []
url = "http://kosmotique.org/feed.xml"
doc = Nokogiri::HTML URI.open(url)
doc.css("entry").each do |entry|
begin
ev = Event::new
ev.title = entry.css("title").text
ev.url = entry.css("link").attr "href"
ev.date = Time.parse entry.css("published").text
events << ev
rescue
STDERR.puts "Omitting: #{$!}"
STDERR.puts $!.backtrace
end
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:Kosmotique, Martin-Luther-Str. 13, Dresden
END:VEVENT
<% end %>
END:VCALENDAR
EOF
puts ical.result