This page must use the Rübÿ Spëëd Mëtäl Cödïng template!!!111
This commit is contained in:
parent
287122c1b9
commit
9bd28f0602
|
@ -1,11 +1,7 @@
|
||||||
[[Kategorie:Ruby]]
|
[[Kategorie:Ruby]]
|
||||||
Der [[Date Determinator]] ist ein MediaWiki-Bot, welcher Terminfindungen vereinfachen sollen. Die Eingabe passiert als YAML, die Ausgabe kann vom Bot periodisch als hybsche Tabelle erstellt werden.
|
Der [[Date Determinator]] ist ein MediaWiki-Bot, welcher Terminfindungen vereinfachen sollen. Die Eingabe passiert als YAML, die Ausgabe kann vom Bot periodisch als hybsche Tabelle erstellt werden.
|
||||||
|
|
||||||
|
|
||||||
=Beispiele=
|
=Beispiele=
|
||||||
|
|
||||||
==CodingNight zu dritt==
|
==CodingNight zu dritt==
|
||||||
|
|
||||||
'''Eingabe:'''
|
'''Eingabe:'''
|
||||||
BEGIN DATA "Test"
|
BEGIN DATA "Test"
|
||||||
Cool Hacker:
|
Cool Hacker:
|
||||||
|
@ -18,7 +14,6 @@ Der [[Date Determinator]] ist ein MediaWiki-Bot, welcher Terminfindungen vereinf
|
||||||
24.5.: jo
|
24.5.: jo
|
||||||
23.5.: yezz!
|
23.5.: yezz!
|
||||||
END DATA
|
END DATA
|
||||||
|
|
||||||
'''Ausgabe:'''
|
'''Ausgabe:'''
|
||||||
<!-- BEGIN TABLE "Test" -->
|
<!-- BEGIN TABLE "Test" -->
|
||||||
{| border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;"
|
{| border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;"
|
||||||
|
@ -49,11 +44,8 @@ Der [[Date Determinator]] ist ein MediaWiki-Bot, welcher Terminfindungen vereinf
|
||||||
|'''1'''
|
|'''1'''
|
||||||
|}
|
|}
|
||||||
<!-- END TABLE -->
|
<!-- END TABLE -->
|
||||||
|
|
||||||
==Realitätsabgleich 2==
|
==Realitätsabgleich 2==
|
||||||
|
|
||||||
''Hier sind die Daten in einem HTML-Kommentar. '''Artikel bearbeiten''' um zu schauen.''
|
''Hier sind die Daten in einem HTML-Kommentar. '''Artikel bearbeiten''' um zu schauen.''
|
||||||
|
|
||||||
<!-- BEGIN DATA "R2"
|
<!-- BEGIN DATA "R2"
|
||||||
Astro:
|
Astro:
|
||||||
16.6.: j
|
16.6.: j
|
||||||
|
@ -133,9 +125,7 @@ toidinamai:
|
||||||
23.6.: j
|
23.6.: j
|
||||||
24.6.: j
|
24.6.: j
|
||||||
25.6.: j
|
25.6.: j
|
||||||
|
|
||||||
END DATA -->
|
END DATA -->
|
||||||
|
|
||||||
<!-- BEGIN TABLE "R2" -->
|
<!-- BEGIN TABLE "R2" -->
|
||||||
{| border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;"
|
{| border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;"
|
||||||
|-
|
|-
|
||||||
|
@ -252,11 +242,8 @@ END DATA -->
|
||||||
|'''3'''
|
|'''3'''
|
||||||
|}
|
|}
|
||||||
<!-- END TABLE -->
|
<!-- END TABLE -->
|
||||||
|
|
||||||
=Source=
|
=Source=
|
||||||
|
|
||||||
Open-source, yada-yada!
|
Open-source, yada-yada!
|
||||||
|
|
||||||
==date_determinator.rb==
|
==date_determinator.rb==
|
||||||
<pre>
|
<pre>
|
||||||
WIKI_USER = 'AstRobot'
|
WIKI_USER = 'AstRobot'
|
||||||
|
@ -265,28 +252,21 @@ PAGE = 'Benutzer:Astro/Date_Determinator'
|
||||||
WIKI = 'http://wiki.c3d2.de/wikipgedia'
|
WIKI = 'http://wiki.c3d2.de/wikipgedia'
|
||||||
HTTP_USER = 'eris'
|
HTTP_USER = 'eris'
|
||||||
HTTP_PASSWORD = '...'
|
HTTP_PASSWORD = '...'
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'mediawiki'
|
require 'mediawiki'
|
||||||
|
|
||||||
include MediaWiki
|
include MediaWiki
|
||||||
|
|
||||||
class DateUser
|
class DateUser
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def initialize(name, hsh)
|
def initialize(name, hsh)
|
||||||
@name = name
|
@name = name
|
||||||
@hsh = hsh
|
@hsh = hsh
|
||||||
end
|
end
|
||||||
|
|
||||||
def dates
|
def dates
|
||||||
@hsh.keys
|
@hsh.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
def day(d)
|
def day(d)
|
||||||
@hsh[d]
|
@hsh[d]
|
||||||
end
|
end
|
||||||
|
|
||||||
def day_class(d)
|
def day_class(d)
|
||||||
if day(d) == nil
|
if day(d) == nil
|
||||||
nil
|
nil
|
||||||
|
@ -298,7 +278,6 @@ class DateUser
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def day_style(d)
|
def day_style(d)
|
||||||
case day_class(d)
|
case day_class(d)
|
||||||
when nil then ""
|
when nil then ""
|
||||||
|
@ -308,7 +287,6 @@ class DateUser
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DateData
|
class DateData
|
||||||
def initialize(yaml)
|
def initialize(yaml)
|
||||||
@users = []
|
@users = []
|
||||||
|
@ -322,19 +300,16 @@ class DateData
|
||||||
@error = e.to_s
|
@error = e.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def table
|
def table
|
||||||
return @error if @error
|
return @error if @error
|
||||||
|
|
||||||
s = ''
|
s = ''
|
||||||
|
|
||||||
##
|
##
|
||||||
# Collect dates
|
# Collect dates
|
||||||
##
|
##
|
||||||
dates = []
|
dates = []
|
||||||
dates_yes = {}
|
dates_yes = {}
|
||||||
@users.each { |user| dates += user.dates }
|
@users.each { |user| dates += user.dates }
|
||||||
|
|
||||||
##
|
##
|
||||||
# Sort dates
|
# Sort dates
|
||||||
##
|
##
|
||||||
|
@ -358,7 +333,6 @@ class DateData
|
||||||
a <=> b
|
a <=> b
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# Construct header
|
# Construct header
|
||||||
##
|
##
|
||||||
|
@ -367,7 +341,6 @@ class DateData
|
||||||
s += "!#{date}\n"
|
s += "!#{date}\n"
|
||||||
dates_yes[date] = 0
|
dates_yes[date] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# Construct rows
|
# Construct rows
|
||||||
##
|
##
|
||||||
|
@ -378,7 +351,6 @@ class DateData
|
||||||
dates_yes[date] += 1 if user.day_class(date) == true
|
dates_yes[date] += 1 if user.day_class(date) == true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# Build summary
|
# Build summary
|
||||||
##
|
##
|
||||||
|
@ -389,13 +361,9 @@ class DateData
|
||||||
s += "|}"
|
s += "|}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wiki = Wiki.new(WIKI, HTTP_USER, HTTP_PASSWORD)
|
wiki = Wiki.new(WIKI, HTTP_USER, HTTP_PASSWORD)
|
||||||
wiki.login(WIKI_USER, WIKI_PASSWORD)
|
wiki.login(WIKI_USER, WIKI_PASSWORD)
|
||||||
page = wiki.article(PAGE)
|
page = wiki.article(PAGE)
|
||||||
|
|
||||||
datasets = {}
|
datasets = {}
|
||||||
current_data_name = nil
|
current_data_name = nil
|
||||||
current_data_yaml = ''
|
current_data_yaml = ''
|
||||||
|
@ -411,45 +379,34 @@ page.text.split(/\n/).each { |line|
|
||||||
current_data_yaml += "#{line}\n"
|
current_data_yaml += "#{line}\n"
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
text_old = page.text.dup
|
text_old = page.text.dup
|
||||||
|
|
||||||
signature = /(<!-- BEGIN TABLE ")(.+?)(" -->)(.+?)(<!-- END TABLE -->)/m
|
signature = /(<!-- BEGIN TABLE ")(.+?)(" -->)(.+?)(<!-- END TABLE -->)/m
|
||||||
page.text.gsub!(signature) { |part|
|
page.text.gsub!(signature) { |part|
|
||||||
begin1,name,begin2,obsolete,end1 = part.match(signature).to_a[1..-1]
|
begin1,name,begin2,obsolete,end1 = part.match(signature).to_a[1..-1]
|
||||||
table = datasets[name] ? datasets[name].table : "DATA #{name} not found!"
|
table = datasets[name] ? datasets[name].table : "DATA #{name} not found!"
|
||||||
"#{begin1}#{name}#{begin2}\n#{table}\n#{end1}"
|
"#{begin1}#{name}#{begin2}\n#{table}\n#{end1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
page.submit('Date Determinator run') if page.text != text_old
|
page.submit('Date Determinator run') if page.text != text_old
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
==mediawiki.rb==
|
==mediawiki.rb==
|
||||||
<pre>
|
<pre>
|
||||||
require 'http-access2'
|
require 'http-access2'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'rexml/document'
|
require 'rexml/document'
|
||||||
|
|
||||||
module MediaWiki
|
module MediaWiki
|
||||||
class Wiki
|
class Wiki
|
||||||
##
|
##
|
||||||
# HTTPAccess2 object, must be accessible by the Wiki's
|
# HTTPAccess2 object, must be accessible by the Wiki's
|
||||||
# Article children
|
# Article children
|
||||||
attr_accessor :http
|
attr_accessor :http
|
||||||
|
|
||||||
def initialize(url, auth_name=nil, auth_password=nil)
|
def initialize(url, auth_name=nil, auth_password=nil)
|
||||||
@url = (url =~ /\/$/) ? url : "#{url}/"
|
@url = (url =~ /\/$/) ? url : "#{url}/"
|
||||||
|
|
||||||
@http = HTTPAccess2::Client.new(nil, 'Ruby-MediaWiki::Wiki/0.1')
|
@http = HTTPAccess2::Client.new(nil, 'Ruby-MediaWiki::Wiki/0.1')
|
||||||
|
|
||||||
add_auth(url, auth_name, auth_password) if auth_name and auth_password
|
add_auth(url, auth_name, auth_password) if auth_name and auth_password
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_auth(uri, auth_name, auth_password)
|
def add_auth(uri, auth_name, auth_password)
|
||||||
@http.set_basic_auth(uri, auth_name, auth_password)
|
@http.set_basic_auth(uri, auth_name, auth_password)
|
||||||
end
|
end
|
||||||
|
|
||||||
def login(username, password)
|
def login(username, password)
|
||||||
postdata = "wpName=#{CGI::escape(username)}&wpPassword=#{CGI::escape(password)}&wpLoginattempt="
|
postdata = "wpName=#{CGI::escape(username)}&wpPassword=#{CGI::escape(password)}&wpLoginattempt="
|
||||||
result = @http.post_content(article_url('Special:Userlogin'), postdata)
|
result = @http.post_content(article_url('Special:Userlogin'), postdata)
|
||||||
|
@ -457,7 +414,6 @@ module MediaWiki
|
||||||
raise "Unable to authenticate as #{username}"
|
raise "Unable to authenticate as #{username}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Return a new article with the given name
|
# Return a new article with the given name
|
||||||
# name:: [String] Article name
|
# name:: [String] Article name
|
||||||
|
@ -465,13 +421,11 @@ module MediaWiki
|
||||||
def article(name)
|
def article(name)
|
||||||
Article.new(self, name)
|
Article.new(self, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Return
|
# Return
|
||||||
def article_url(name)
|
def article_url(name)
|
||||||
"#{@url}index.php?title=#{CGI::escape(name)}"
|
"#{@url}index.php?title=#{CGI::escape(name)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Return a hash of special pages:
|
# Return a hash of special pages:
|
||||||
# 'Link title' => 'Article name'
|
# 'Link title' => 'Article name'
|
||||||
|
@ -483,30 +437,25 @@ module MediaWiki
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Article
|
class Article
|
||||||
attr_accessor :name, :text
|
attr_accessor :name, :text
|
||||||
|
|
||||||
def initialize(wiki, name, load_text=true)
|
def initialize(wiki, name, load_text=true)
|
||||||
@wiki = wiki
|
@wiki = wiki
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
@text = nil
|
@text = nil
|
||||||
@xhtml = nil
|
@xhtml = nil
|
||||||
@xhtml_cached = false
|
@xhtml_cached = false
|
||||||
@wp_edittoken = nil
|
@wp_edittoken = nil
|
||||||
@wp_edittime = nil
|
@wp_edittime = nil
|
||||||
|
|
||||||
reload if load_text
|
reload if load_text
|
||||||
end
|
end
|
||||||
|
|
||||||
def xhtml
|
def xhtml
|
||||||
unless @xhtml_cached
|
unless @xhtml_cached
|
||||||
xhtml_reload
|
xhtml_reload
|
||||||
end
|
end
|
||||||
@xhtml
|
@xhtml
|
||||||
end
|
end
|
||||||
|
|
||||||
def xhtml_reload
|
def xhtml_reload
|
||||||
html = @wiki.http.get_content("#{@wiki.article_url(@name)}")
|
html = @wiki.http.get_content("#{@wiki.article_url(@name)}")
|
||||||
html.scan(/<!-- start content -->(.+)<!-- end content -->/m) { |content,|
|
html.scan(/<!-- start content -->(.+)<!-- end content -->/m) { |content,|
|
||||||
|
@ -515,7 +464,6 @@ module MediaWiki
|
||||||
|
|
||||||
@xhtml_cached = true
|
@xhtml_cached = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload
|
def reload
|
||||||
puts "Loading #{@wiki.article_url(@name)}&action=edit"
|
puts "Loading #{@wiki.article_url(@name)}&action=edit"
|
||||||
doc = REXML::Document.new(@wiki.http.get_content("#{@wiki.article_url(@name)}&action=edit")).root
|
doc = REXML::Document.new(@wiki.http.get_content("#{@wiki.article_url(@name)}&action=edit")).root
|
||||||
|
@ -529,7 +477,6 @@ module MediaWiki
|
||||||
# wpEditToken might be missing, that's ok
|
# wpEditToken might be missing, that's ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# TODO: minor_edit, watch_this
|
# TODO: minor_edit, watch_this
|
||||||
def submit(summary, minor_edit=false, watch_this=false)
|
def submit(summary, minor_edit=false, watch_this=false)
|
||||||
|
@ -541,3 +488,5 @@ module MediaWiki
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
{{Rübÿ Spëëd Mëtäl Cödïng}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user