votebot/start.rb

34 lines
986 B
Ruby
Executable File

#!/usr/bin/ruby
require './Wiki.rb'
#TODO: don't tag the category pages and redirects
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
if page['title'] == 'Main Page' || page['title'] == 'עמוד ראשי' then
next
end
puts page['title']
page_text = wiki.get_text(page['title']).body.force_encoding("UTF-8")
changed = false
if not page_text.include?("<vote type=1 />") and
not page_text.include("REDIRECT")
then
page_text = page_text + "\n\n<vote type=1 />"
changed = true
end
if not page_text.include?("<iusethis />") and
not page_text.include("REDIRECT")
then
page_text = page_text + "\n\n<iusethis />"
changed = true
end
if changed then
wiki.create_page(page['title'], page_text)
end
end
end