neingeist
/
neinomaten
Archived
1
0
Fork 0

bessere termine

master
neingeist 19 years ago
parent 429c18b54d
commit 85295f82e8

@ -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])

@ -206,9 +206,20 @@ class WikiBot
fields = {}
fields_string = get_raw(title).scan(template_re)[0][0]
fields_string.split(/\|/).each do |field|
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

@ -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 + " <wiki-user> <wiki-password>\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")