riesa-efau-kalender: fix
This commit is contained in:
parent
d2406e63a2
commit
1e60b4e947
|
@ -5,28 +5,25 @@ require 'open-uri'
|
||||||
require 'nokogiri'
|
require 'nokogiri'
|
||||||
require 'erb'
|
require 'erb'
|
||||||
|
|
||||||
MONTHS = [
|
|
||||||
"Januar", "Februar", "März", "April",
|
|
||||||
"Mai", "Juni", "Juli", "August",
|
|
||||||
"September", "Oktober", "November", "Dezember",
|
|
||||||
]
|
|
||||||
|
|
||||||
def fmt_time t
|
def fmt_time t
|
||||||
t.strftime "%Y%m%dT%H%M%S"
|
t.strftime "%Y%m%dT%H%M%S"
|
||||||
end
|
end
|
||||||
|
|
||||||
class Event
|
class Event
|
||||||
attr_accessor :name, :location, :link, :image
|
attr_accessor :name, :location, :link, :image
|
||||||
attr_reader :date
|
attr_reader :dtstart, :dtend
|
||||||
|
|
||||||
def date=(s)
|
def date=(s)
|
||||||
if s =~ /(\d{1,2})\. (.+?) (\d{4}), (\d\d):(\d\d) Uhr/
|
if s =~ /(\d{1,2})\.\s*(\d{1,2})\.\s*(\d{4}),\s*(\d+):(\d+)\s*-\s*(\d+):(\d+) Uhr/
|
||||||
year = $3.to_i
|
year = $3.to_i
|
||||||
month = MONTHS.index($2) + 1
|
month = $2.to_i
|
||||||
day = $1.to_i
|
day = $1.to_i
|
||||||
hour = $4.to_i
|
start_hour = $4.to_i
|
||||||
minute = $5.to_i
|
start_minute = $5.to_i
|
||||||
@date = Time::local year, month, day, hour, minute, 0
|
end_hour = $6.to_i
|
||||||
|
end_minute = $7.to_i
|
||||||
|
@dtstart = Time::local year, month, day, start_hour, start_minute, 0
|
||||||
|
@dtend = Time::local year, month, day, end_hour, end_minute, 0
|
||||||
else
|
else
|
||||||
raise "Invalid date: #{s.inspect}"
|
raise "Invalid date: #{s.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -35,20 +32,23 @@ end
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
url = "https://riesa-efau.de/index.php?id=87"
|
urls = [ "https://riesa-efau.de/index.php?id=87" ]
|
||||||
|
while urls.size > 0
|
||||||
|
url = urls.shift
|
||||||
doc = Nokogiri::HTML URI.open(url)
|
doc = Nokogiri::HTML URI.open(url)
|
||||||
doc.css(".tx-cal-controller .vevent").each do |vevent|
|
doc.css(".vevent").each do |vevent|
|
||||||
ev = Event::new
|
ev = Event::new
|
||||||
ev.name = vevent.css("h3").children[0].text
|
next if vevent.css("h3").children.size == 0
|
||||||
ev.location = vevent.css(".location").text
|
ev.name = vevent.css("h3").children[0].text.strip
|
||||||
.sub(/ *\.\.\.[^\.]*$/, "")
|
ev.location = vevent.css(".location").text.strip.gsub(/[\r\n\t]+/, ", ") + ", Riesa Efau"
|
||||||
ev.date = vevent.css(".datum").text
|
ev.date = vevent.css(".datum").text
|
||||||
ev.link = URI.join url, vevent.css(".url").attr('href').value
|
ev.link = URI.join url, vevent.css("a[1]").attr('href')
|
||||||
ev.image = URI.join url, vevent.css(".images img").attr('src').value
|
ev.image = URI.join url, vevent.css(".images img").attr('src')
|
||||||
events << ev
|
events << ev
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
events.sort_by! { |ev| ev.date }
|
events.sort_by! { |ev| ev.dtstart }
|
||||||
|
|
||||||
ical = ERB::new <<~EOF
|
ical = ERB::new <<~EOF
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
|
@ -60,8 +60,8 @@ ical = ERB::new <<~EOF
|
||||||
METHOD:PUBLISH
|
METHOD:PUBLISH
|
||||||
CLASS:PUBLIC
|
CLASS:PUBLIC
|
||||||
UID:<%= ev.link %>
|
UID:<%= ev.link %>
|
||||||
DTSTART:<%= fmt_time(ev.date) %>
|
DTSTART:<%= fmt_time(ev.dtstart) %>
|
||||||
DTEND:<%= fmt_time(ev.date + 2 * 3600) %>
|
DTEND:<%= fmt_time(ev.dtend) %>
|
||||||
SUMMARY:<%= ev.name %>
|
SUMMARY:<%= ev.name %>
|
||||||
LOCATION:<%= ev.location %>
|
LOCATION:<%= ev.location %>
|
||||||
URL:<%= ev.link %>
|
URL:<%= ev.link %>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user