From 8e5e23360fb4ac5ce97d21e56282186293e8cc31 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 12 Jan 2023 20:52:45 +0100 Subject: [PATCH] kosmotique: add --- default.nix | 1 + kosmotique/scrape.rb | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 kosmotique/scrape.rb diff --git a/default.nix b/default.nix index 60fe679..40d0f2b 100644 --- a/default.nix +++ b/default.nix @@ -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; } diff --git a/kosmotique/scrape.rb b/kosmotique/scrape.rb new file mode 100644 index 0000000..4e0d1c3 --- /dev/null +++ b/kosmotique/scrape.rb @@ -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