neingeist
/
neinomaten
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

83 lines
2.3 KiB
Plaintext

19 years ago
#!/usr/bin/env ruby
require 'mediawikibot'
19 years ago
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
#----------------------------------------------------------------------------
19 years ago
if ARGV.size() != 2
$stderr.print($0 + " <wiki-user> <wiki-password>\n")
exit(1)
end
19 years ago
b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/")
19 years ago
b.login(ARGV[0], ARGV[1])
#----------------------------------------------------------------------------
19 years ago
termine = []
19 years ago
template = "Vorlage:Radio Chaotica-Sendung"
b.get_what_uses_template(template).each do |page|
if erste_sendung = b.parse_template(page, template)["erste_sendung"]
termin = {}
termin["datum"] = erste_sendung.gsub(/\s*um\s*\d+:\d+$/,"")
termin["uhrzeit"] = "16:00"
termin["beschreibung"] = "[[" + page + "]]"
termin["ort"] = "[http://www.querfunk.de Querfunk]"
termine.push(termin)
else
$stderr.print(page, ": erste_sendung nicht gesetzt")
end
end
#----------------------------------------------------------------------------
template = "Vorlage:Termin"
b.get_what_uses_template(template).each do |page|
termin = b.parse_template(page, template)
termine.push(termin)
end
#----------------------------------------------------------------------------
19 years ago
# Get a real date
termine.each do |termin|
termin["date"] = Date.parse(datum2isodate(termin["datum"]))
end
19 years ago
termine = termine.sort do |x,y|
19 years ago
x["date"] <=> y["date"]
19 years ago
end
19 years ago
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)
19 years ago
b.edit("Benutzer:Neingeist/Termine", body, "Test")