More than one wiki support, IUseThis support

This commit is contained in:
Alexander Yakovlev 2017-01-19 16:50:15 +07:00
parent b904dbf5c6
commit 96ee214be3
2 changed files with 25 additions and 12 deletions

View file

@ -7,11 +7,10 @@ class Wiki
@text = nil
@dummy = false
def initialize
config = YAML::load_file(File.join(__dir__, 'config.yaml'))
@client = MWClient.new config["url"]
@client.log_in config["username"], config["password"]
@dummy = config["dummy"]
def initialize(url, username, password, dummy = false)
@client = MWClient.new url
@client.log_in username, password
@dummy = dummy
end
def create_page(name, content)

View file

@ -1,12 +1,26 @@
#!/usr/bin/ruby
require './Wiki.rb'
wiki = Wiki.new
list = wiki.get_list()['allpages']
for page in list do
page_text = wiki.get_text(page['title']).body
if page_text.match(/\[\[Category\:Jokes\]\]/) and not page_text.match(/<vote type=1 \/>/) then
page_text = page_text + "\n\n<vote type=1 />"
wiki.create_page(page['title'], page_text)
config = YAML::load_file(File.join(__dir__, 'config.yaml'))
config["sites"].each do |site|
wiki = Wiki.new(site["url"], site["username"], site["password"], config["dummy"])
list = wiki.get_list()['allpages']
for page in list do
page_text = wiki.get_text(page['title']).body
changed = false
if not page_text.include?("[[Category:#{config["category"]}]]") then
next
end
if not page_text.include?("<vote type=1 />") then
page_text = page_text + "\n\n<vote type=1 />"
changed = true
end
if not page_text.include?("<iusethis />") then
page_text = page_text + "\n\n<iusethis />"
changed = true
end
if changed then
wiki.create_page(page['title'], page_text)
end
end
end