bessere termine
This commit is contained in:
parent
429c18b54d
commit
85295f82e8
3 changed files with 52 additions and 19 deletions
|
@ -6,8 +6,6 @@ if ARGV.size() != 2
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/")
|
b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/")
|
||||||
b.login(ARGV[0], ARGV[1])
|
b.login(ARGV[0], ARGV[1])
|
||||||
|
|
||||||
|
|
|
@ -206,9 +206,20 @@ class WikiBot
|
||||||
fields = {}
|
fields = {}
|
||||||
|
|
||||||
fields_string = get_raw(title).scan(template_re)[0][0]
|
fields_string = get_raw(title).scan(template_re)[0][0]
|
||||||
fields_string.split(/\|/).each do |field|
|
|
||||||
(key, value) = field.split(/=/)
|
inlink = 0
|
||||||
fields[key] = value
|
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
|
end
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
|
|
@ -1,5 +1,29 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'mediawikibot'
|
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
|
if ARGV.size() != 2
|
||||||
$stderr.print($0 + " <wiki-user> <wiki-password>\n")
|
$stderr.print($0 + " <wiki-user> <wiki-password>\n")
|
||||||
|
@ -9,9 +33,9 @@ end
|
||||||
b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/")
|
b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/")
|
||||||
b.login(ARGV[0], ARGV[1])
|
b.login(ARGV[0], ARGV[1])
|
||||||
|
|
||||||
termine = []
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
termine = []
|
||||||
|
|
||||||
template = "Vorlage:Radio Chaotica-Sendung"
|
template = "Vorlage:Radio Chaotica-Sendung"
|
||||||
b.get_what_uses_template(template).each do |page|
|
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|
|
termine = termine.sort do |x,y|
|
||||||
def datum2isodate(datum)
|
x["date"] <=> y["date"]
|
||||||
return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1]
|
|
||||||
end
|
|
||||||
datum2isodate(x["datum"]) <=> datum2isodate(y["datum"])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
body = '{| border=1 cellspacing="0" cellpadding="5" style="border-collapse:collapse;"'
|
vergangene_termine = termine.clone.delete_if { |t| t["date"] >= Date.today() }
|
||||||
body += "\n"
|
kommende_termine = termine.clone.delete_if { |t| t["date"] < Date.today() }
|
||||||
termine.each do |termin|
|
|
||||||
body += "| " + termin["datum"] + "\n"
|
body = "== Vergangene Termine ==\n"
|
||||||
body += "| " + termin["beschreibung"] + "\n"
|
body += table_termine(vergangene_termine)
|
||||||
body += "|-\n"
|
|
||||||
end
|
body += "\n== Kommende Termine ==\n"
|
||||||
body += "|}"
|
body += table_termine(kommende_termine)
|
||||||
|
|
||||||
#puts body
|
|
||||||
b.edit("Benutzer:Neingeist/Termine", body, "Test")
|
b.edit("Benutzer:Neingeist/Termine", body, "Test")
|
||||||
|
|
Reference in a new issue