User:GemmaBot/add lostfilms.py

From Wikisource
Jump to navigation Jump to search
# import re
import pywikibot
# import random
import time

fhandle = open('filmparse.txt', 'r')

full_list = fhandle.read()

list_by_page = full_list.split("\n----\n")

# print(list_by_page[3])

# for page in list_by_page:
#   other_letter = re.findall("\#\#(.)\#\#", page)
#   if len(other_letter) > 1:
#     other_letter = other_letter[1]
#     letter_coord.append({other_letter: page_num})
#   page_num += 1

# print(letter_coord)


page_num = 12
filename = "7,200 Lost U.S. Silent Feature Films (1912-29) (2021-02-04).pdf"
work = "7,200 Lost U.S. Silent Feature Films (1912-29) (2021-02-04)"

page_num = 3


for p in list_by_page:
    pagename = f"Page:{filename}/{page_num}"
    print(f"Doing {pagename}...")
    site = pywikibot.Site()

    page = pywikibot.Page(site, pagename)
    page.text = f"<noinclude><pagequality level=\"3\" user=\"PseudoSkull\" /></noinclude>{p}<noinclude></noinclude>"
    time.sleep(50)
    page.save("RIP to every one of these lost films except ''The Fall of a Nation'' and other horribly immoral ones. You will all be missed...")
    print(pagename)
    page_num += 1

letter_coord = {'0-9': 1, 'A': 2, 'B': 7, 'C': 19, 'D': 28, 'E': 36, 'F': 38, 'G': 47, 'H': 54, 'I': 64, 'J': 68, 'K': 70, 'L': 71, 'M': 81, 'N': 93, 'O': 96, 'P': 100, 'Q': 107, 'R': 108, 'S': 115, 'T': 131, 'U': 141, 'V': 143, 'W': 144, 'Y': 156, 'Z': 157}
letter_locations = list(letter_coord.items())

count = 0
for letter in letter_locations:
  current_letter = letter[0]
  start_page = letter[1]
  if count != 0:
    previous_letter = f'../{letter_locations[count-1][0]}/'
  else:
    previous_letter = '../|Front matter'
  if count != len(letter_locations)-1:
    next_letter = f'../{letter_locations[count+1][0]}/'
    end_page = letter_locations[count+1][1]
  else:
    next_letter = '../|Return to front matter'
    end_page = start_page

  text_to_insert = f"""{{{{header
 | title      = [[../|7,200 Lost U.S. Silent Feature Films (1912-29)]]
 | author     = Stephen C. Leggett
 | translator = 
 | section    = {current_letter}
 | previous   = [[{previous_letter}]]
 | next       = [[{next_letter}]]
 | year       = 
 | notes      = 
}}}}

<pages index="7,200 Lost U.S. Silent Feature Films (1912-29) (2021-02-04).pdf" from={start_page} to={end_page} onlysection="{current_letter}" />
"""
  pagename = f"{work}/{current_letter}"
  print(f"Transcluding {pagename}...")
  site = pywikibot.Site()

  page = pywikibot.Page(site, pagename)
  page.text = f"{text_to_insert}"
  time.sleep(50)
  page.save("RIP to every one of these lost films except ''The Fall of a Nation'' and other horribly immoral ones. You will all be missed...")
  count += 1

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