Initial commit
This commit is contained in:
commit
e015f90252
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
config.yaml
|
37
Gemfile.lock
Normal file
37
Gemfile.lock
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
domain_name (0.5.20161129)
|
||||||
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
|
faraday (0.11.0)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
|
faraday-cookie_jar (0.0.6)
|
||||||
|
faraday (>= 0.7.4)
|
||||||
|
http-cookie (~> 1.0.0)
|
||||||
|
faraday_middleware (0.11.0)
|
||||||
|
faraday (>= 0.7.4, < 1.0)
|
||||||
|
http-cookie (1.0.3)
|
||||||
|
domain_name (~> 0.5)
|
||||||
|
mediawiki_api (0.7.0)
|
||||||
|
faraday (~> 0.9, >= 0.9.0)
|
||||||
|
faraday-cookie_jar (~> 0.0, >= 0.0.6)
|
||||||
|
faraday_middleware (~> 0.10, >= 0.10.0)
|
||||||
|
mini_portile2 (2.1.0)
|
||||||
|
multipart-post (2.0.0)
|
||||||
|
nokogiri (1.7.0.1)
|
||||||
|
mini_portile2 (~> 2.1.0)
|
||||||
|
pandoc-ruby (2.0.1)
|
||||||
|
unf (0.1.4)
|
||||||
|
unf_ext
|
||||||
|
unf_ext (0.0.7.2)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
mediawiki_api
|
||||||
|
nokogiri
|
||||||
|
pandoc-ruby
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
1.13.6
|
7
MWClient.rb
Normal file
7
MWClient.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'mediawiki_api'
|
||||||
|
|
||||||
|
class MWClient < MediawikiApi::Client
|
||||||
|
def get_wikitext(title)
|
||||||
|
@conn.get '/index.php', action: 'raw', title: title
|
||||||
|
end
|
||||||
|
end
|
10
README.md
Normal file
10
README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# A MediaWiki bot for VoteNY widget
|
||||||
|
|
||||||
|
Adds a **VoteNY** widget to every page in "Jokes" category.
|
||||||
|
|
||||||
|
### Script configuration
|
||||||
|
See `config.yaml`:
|
||||||
|
|
||||||
|
* `username`: wiki user login
|
||||||
|
* `password`: wiki user password
|
||||||
|
* `dummy`: test mode if `true`
|
45
Wiki.rb
Normal file
45
Wiki.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
require 'yaml'
|
||||||
|
require 'json'
|
||||||
|
require './MWClient.rb'
|
||||||
|
|
||||||
|
class Wiki
|
||||||
|
@client = nil
|
||||||
|
@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"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_page(name, content)
|
||||||
|
if not @dummy then
|
||||||
|
@client.create_page name, content
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
if @dummy then
|
||||||
|
puts "Draft mode.\n"
|
||||||
|
end
|
||||||
|
puts @text
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def exists?(name)
|
||||||
|
status = @client.get_wikitext(name).status
|
||||||
|
if status.to_i == 404 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
def get_list
|
||||||
|
list = @client.query list: 'allpages'
|
||||||
|
return list.data
|
||||||
|
end
|
||||||
|
def get_text(page_title)
|
||||||
|
return @client.get_wikitext(page_title)
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_accessor :dummy
|
||||||
|
end
|
13
start.rb
Executable file
13
start.rb
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/ruby
|
||||||
|
require 'pp'
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue