diff --git a/die-ewigen-neinomaten b/die-ewigen-neinomaten index 64911d2..9ac3815 100755 --- a/die-ewigen-neinomaten +++ b/die-ewigen-neinomaten @@ -1,4 +1,4 @@ #!/bin/sh -./neinomat-uebersichten $* -./neinomat-radio-chaotica $* -./neinomat-termine $* +./neinomat-uebersichten +./neinomat-radio-chaotica +./neinomat-termine diff --git a/neinomat-termine b/neinomat-termine index d56b279..ae41dbd 100755 --- a/neinomat-termine +++ b/neinomat-termine @@ -1,9 +1,38 @@ #!/usr/bin/env ruby -require 'mediawikibot' +$:.unshift('vendor/ruby-mediawiki/lib') +$:.unshift('vendor/htree') +require 'mediawiki/dotfile' +@wiki = MediaWiki.dotfile(nil,'entropia') + require 'date' #---------------------------------------------------------------------------- +def parse_template(title, template) + template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}") + + fields = {} + + fields_string = @wiki.article(title).text.scan(template_re)[0][0] + + inlink = 0 + field = "" + fields_string += "|" unless fields_string.match(/\|$/) + fields_string.split(//).each do |c| + if c == "|" && inlink == 0 + (key, value) = field.split(/=/) + fields[key] = value + field = "" + else + inlink += 1 if c == "[" + inlink -= 1 if c == "]" + field += c + end + end + + fields +end + def datum2isodate(datum) return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1] end @@ -23,23 +52,12 @@ def table_termine (t) return body end -#---------------------------------------------------------------------------- - -if ARGV.size() != 2 - $stderr.print($0 + " \n") - exit(1) -end - -b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/") -b.login(ARGV[0], ARGV[1]) - - #---------------------------------------------------------------------------- termine = [] template = "Vorlage:Radio Chaotica-Sendung" -b.get_what_uses_template(template).each do |page| - if erste_sendung = b.parse_template(page, template)["erste_sendung"] +@wiki.article(template).what_links_here.each do |page| + if erste_sendung = parse_template(page, template)["erste_sendung"] termin = {} termin["datum"] = erste_sendung.gsub(/\s*um\s*\d+:\d+$/,"") termin["uhrzeit"] = "16:00" @@ -54,9 +72,9 @@ end #---------------------------------------------------------------------------- template = "Vorlage:Termin" -b.get_what_uses_template(template).each do |page| - termin = b.parse_template(page, template) - termine.push(termin) +@wiki.article(template).what_links_here.each do |page| + termin = parse_template(page, template) + termine.push(termin) end #---------------------------------------------------------------------------- @@ -79,4 +97,6 @@ body += table_termine(vergangene_termine) body += "\n== Kommende Termine ==\n" body += table_termine(kommende_termine) -b.edit("Benutzer:Neingeist/Termine", body, "Test") +a = @wiki.article("Benutzer:Neingeist/Termine") +a.text = body +a.submit("wiki ex machina")