diff --git a/stadtwiki/stadtwiki-googlecalendar b/stadtwiki/stadtwiki-googlecalendar new file mode 100755 index 0000000..fe8a575 --- /dev/null +++ b/stadtwiki/stadtwiki-googlecalendar @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby +$:.unshift('vendor/ruby-mediawiki/lib') +require 'mediawiki/dotfile' +require 'http-access2' +require 'vpim/icalendar' +include Vpim + +$ical_url = "http://www.google.com/calendar/ical/nsb7jkat2efmkfs85qcbvouk8g@group.calendar.google.com/public/basic.ics" +$st = - 3*24*3600 +$en = +180*24*3600 + +def get_events() + @client = HTTPAccess2::Client.new() + ical = @client.get_content($ical_url) + events = [] + Icalendar.decode(ical).each do |publish| + publish.events.each do |event| + if event.dtstart >= (Time.now+$st) and event.dtstart <= (Time.now+$en) + events.push(event) + end + end + end + return events +end + +@wiki = MediaWiki.dotfile(nil,'stadtwiki') + +body = "Folgende Termine stammen von #{$ical_url}:\n\n" +get_events().sort {|x,y| x.dtstart <=> y.dtstart }.each do |event| + body += "* #{event.dtstart.mday}.#{event.dtstart.month}. #{event.summary}\n" +end + +a = @wiki.article("Benutzer:Neingeist/Termine_aus_Google_Calendar") +a.text = body +a.submit("Import")