User:GemmaBot/noproofread.py

From Wikisource
Jump to navigation Jump to search
import re
import time
print("Importing pywikibot...")
import pywikibot
print("Imported!")

filename = "Ruth of the U.S.A. (IA ruthofusa00balm).pdf"
front_cover = False
back_cover = True

pagename = f"Index:{filename}"
site = pywikibot.Site()

page = pywikibot.Page(site, pagename)
text = page.text

pagelist = []

# get all page numbers from pagelist stagnant

pagelist_start = False
count = 0
for line in text.split("\n"):
    if line == "|Pages=<pagelist":
        pagelist_start = True
        continue
    if line == "/>":
        pagelist_start = False
        break
    if pagelist_start == True:
        count += 1
        if line.endswith("=—"):
            nums = line[:-2]
            if "to" in nums:
                nums = nums.split("to")
                for num in range(int(nums[0]), int(nums[1])+1):
                    pagelist.append(num)
            else:
                pagelist.append(int(nums))
        if line.endswith("=cover"):
            nums = line[:-6]
            if count == 1 and front_cover == True:
                pagelist.append(int(nums))
            if count != 1 and back_cover == True:
                pagelist.append(int(nums))

print(pagelist)

# Insert content into pages

for page_num in pagelist:
    pagename = f"Page:{filename}/{page_num}"
    site = pywikibot.Site()
    page = pywikibot.Page(site, pagename)
    if page.text != "":
        print(page.text)
        continueornot = input(f"WARNING: Page {pagename} has content. Are you sure you want to continue?")
    page.text = """<noinclude><pagequality level="0" user="PseudoSkull" /></noinclude><noinclude></noinclude>"""
    print(f"\nDoing {pagename}...")
    edit_summary = f"Bot: mark page as not needing to be proofread"
    print(edit_summary)
    print("Sleeping 50 seconds...")
    time.sleep(50)
    page.save(edit_summary)
    print("----")

I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible:

I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

Public domainPublic domainfalsefalse