Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 

















User:ZackBot/Infobox-needed

















User page
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
User contributions
User logs
View user groups
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< User:ZackBot

require 'mediawiki_api'
require 'HTTParty'
require 'timeout'
require '../helper'
require 'uri'
require 'colorize'
require_relative './page'

URL = "https://petscan.wmflabs.org/?psid=5950450&format=json"

Helper.read_env_vars(file = '../vars.csv')

@content = HTTParty.get(URL)

client = MediawikiApi::Client.new 'https://en.wikipedia.org/w/api.php'
client.log_in ENV['USERNAME'], ENV['PASSWORD']

pages = @content["*"].first['a']['*'].map do |i|
  i["title"].gsub('_', ' ')
end
puts "Total to do: #{pages.size}"

pages.each do |title|
  puts title

  full_text = client.get_wikitext(title).body
  if Page.parse_page(full_text,title)
    talk_title = "Talk:#{title}"
    begin
      talk_page_text = client.get_wikitext(talk_title).body
      new_text = Page.parse_talk_page(talk_page_text)
      client.edit(title: talk_title, text: new_text, summary: "removing 'needs-infobox' as the page has an infobox")
      puts "- success".colorize(:green)
      sleep 5
    rescue Page::NeedsInfoboxNotFound => e
      Helper.print_message('Raised: "NeedsInfoboxNotFound"')
      Helper.print_link(talk_title)
      next      
    end     
  end
end

puts "DONE!"



module Page
  class NeedsInfoboxNotFound < StandardError; end
  def self.parse_page(full_text, title)
    if has_infobox?(full_text)
      Helper.print_message('HAS INFOBOX')
      Helper.print_link(title)
      return "Has Infobox"
    else
      return nil
    end
  end
  
  NEEDS_INFOBOX = /\|\s*needs-infobox\s*=\s*y(?:es){0,1}\s*/
  def self.parse_talk_page(talk_page_text)
    raise NeedsInfoboxNotFound unless talk_page_text.match?(NEEDS_INFOBOX)
    talk_page_text.gsub(NEEDS_INFOBOX,'')
  end

  INFOBOX = /infobox/i
  def self.has_infobox?(text)
    text.match?(INFOBOX)
  end
end

Retrieved from "https://en.wikipedia.org/w/index.php?title=User:ZackBot/Infobox-needed&oldid=1086846329"





This page was last edited on 8 May 2022, at 18:21 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki