diff --git a/examples/fix-links b/examples/fix-links index 1a44924..8b04926 100755 --- a/examples/fix-links +++ b/examples/fix-links @@ -6,8 +6,6 @@ if ARGV.size() != 2 exit(1) end -#---------------------------------------------------------------------------- - b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/") b.login(ARGV[0], ARGV[1]) diff --git a/mediawikibot.rb b/mediawikibot.rb index 8c76ed0..761656c 100755 --- a/mediawikibot.rb +++ b/mediawikibot.rb @@ -206,9 +206,20 @@ class WikiBot fields = {} fields_string = get_raw(title).scan(template_re)[0][0] - fields_string.split(/\|/).each do |field| - (key, value) = field.split(/=/) - fields[key] = value + + 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 return fields diff --git a/neinomat-termine b/neinomat-termine index 2ead0d0..d56b279 100755 --- a/neinomat-termine +++ b/neinomat-termine @@ -1,5 +1,29 @@ #!/usr/bin/env ruby require 'mediawikibot' +require 'date' + +#---------------------------------------------------------------------------- + +def datum2isodate(datum) + return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1] +end + +def table_termine (t) + body = '{| border=1 cellspacing="0" cellpadding="5" style="border-collapse:collapse;"' + body += "\n" + body += "| Datum \n| Uhrzeit \n| Ort \n| Beschreibung \n|-\n" + t.each do |termin| + body += "| " + termin["datum"].to_s + "\n" + body += "| " + termin["uhrzeit"].to_s + "\n" + body += "| " + termin["ort"].to_s + "\n" + body += "| " + termin["beschreibung"].to_s + "\n" + body += "|-\n" + end + body += "|}" + return body +end + +#---------------------------------------------------------------------------- if ARGV.size() != 2 $stderr.print($0 + " \n") @@ -9,9 +33,9 @@ end b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/") b.login(ARGV[0], ARGV[1]) -termine = [] #---------------------------------------------------------------------------- +termine = [] template = "Vorlage:Radio Chaotica-Sendung" b.get_what_uses_template(template).each do |page| @@ -37,22 +61,22 @@ end #---------------------------------------------------------------------------- +# Get a real date +termine.each do |termin| + termin["date"] = Date.parse(datum2isodate(termin["datum"])) +end termine = termine.sort do |x,y| - def datum2isodate(datum) - return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1] - end - datum2isodate(x["datum"]) <=> datum2isodate(y["datum"]) + x["date"] <=> y["date"] end -body = '{| border=1 cellspacing="0" cellpadding="5" style="border-collapse:collapse;"' -body += "\n" -termine.each do |termin| - body += "| " + termin["datum"] + "\n" - body += "| " + termin["beschreibung"] + "\n" - body += "|-\n" -end -body += "|}" +vergangene_termine = termine.clone.delete_if { |t| t["date"] >= Date.today() } +kommende_termine = termine.clone.delete_if { |t| t["date"] < Date.today() } + +body = "== Vergangene Termine ==\n" +body += table_termine(vergangene_termine) + +body += "\n== Kommende Termine ==\n" +body += table_termine(kommende_termine) -#puts body b.edit("Benutzer:Neingeist/Termine", body, "Test")