#!/usr/bin/env ruby
# encoding: utf-8
require 'mediawiki_api'
require 'HTTParty'
require 'csv'
require 'open-uri'
require './helper'
require 'fileutils'
def exactly_one_time(text, param, regex)
count = text.scan(regex).size
if count > 1
puts "- ERROR: '#{param}' appears more than one time on the page."
return false
elsif count == 0
puts "- ERROR: '#{param}' does not apepar on the page"
return false
end
true
end
INFOBOX_REGEX = /(?=\{\{[Ii]nfobox\sNFL\s(?:player|biography))(\{\{(?>[^{}]++|\g<1>)*}})/
CATEGORY = "[[Category:Pages using infobox NFL player with dbf parameter|dbf parameters]]"
QUERY_URL = "https://petscan.wmflabs.org/?psid=598019&format=json"
Helper.read_env_vars
client = MediawikiApi::Client.new 'https://en.wikipedia.org/w/api.php'
client.log_in ENV'USERNAME', ENV'PASSWORD'
json = JSON.load(open(QUERY_URL))
titles = json"*"].first"a"]["*"].map{ | page| page"title"].gsub("_"," ")}
puts titles.size
# For testing
# pages = File.open('test.txt').read
# pages.each_line do |title|
titles.each do |title|
title.strip!
puts title
full_text = client.get_wikitext(title).body
next unless (exactly_one_time(full_text, "Infobox NFL", INFOBOX_REGEX))
infobox_text = full_text.match(INFOBOX_REGEX)0
infobox_text.gsub!(/\|\s*dbf\s*=.*\n/, "")
full_text.gsub!(INFOBOX_REGEX, infobox_text)
client.(title: title, text: full_text, summary: "Fixing infobox not to use #{CATEGORY}")
puts "- SUCCESS"
end
puts "DONE"
#!/usr/bin/env ruby
# encoding: utf-8
require 'mediawiki_api'
require 'HTTParty'
require 'csv'
require 'open-uri'
require './helper'
require 'fileutils'
def exactly_one_time(text, param, regex)
count = text.scan(regex).size
if count > 1
puts "- ERROR: '#{param}' appears more than one time on the page."
return false
elsif count == 0
puts "- ERROR: '#{param}' does not apepar on the page"
return false
end
true
end
INFOBOX_REGEX = /(?=\{\{[Ii]nfobox\sNFL\s(?:player|biography))(\{\{(?>[^{}]++|\g<1>)*}})/
CATEGORY = "[[Category:Pages using infobox NFL player with dbf parameter|dbf parameters]]"
QUERY_URL = "https://petscan.wmflabs.org/?psid=598019&format=json"
Helper.read_env_vars
client = MediawikiApi::Client.new 'https://en.wikipedia.org/w/api.php'
client.log_in ENV'USERNAME', ENV'PASSWORD'
json = JSON.load(open(QUERY_URL))
titles = json"*"].first"a"]["*"].map{ | page| page"title"].gsub("_"," ")}
puts titles.size
# For testing
# pages = File.open('test.txt').read
# pages.each_line do |title|
titles.each do |title|
title.strip!
puts title
full_text = client.get_wikitext(title).body
next unless (exactly_one_time(full_text, "Infobox NFL", INFOBOX_REGEX))
infobox_text = full_text.match(INFOBOX_REGEX)0
infobox_text.gsub!(/\|\s*dbf\s*=.*\n/, "")
full_text.gsub!(INFOBOX_REGEX, infobox_text)
client.(title: title, text: full_text, summary: "Fixing infobox not to use #{CATEGORY}")
puts "- SUCCESS"
end
puts "DONE"