User:Şêr/rhyme-not-found.py
< User:Şêr
import pywikibot
site = pywikibot.Site("en", "wiktionary")
def read_titles_from_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
titles = file.readlines()
titles = [title.strip() for title in titles]
return titles
file_path = 'page_titles.txt'
page_titles = read_titles_from_file(file_path)
not_found_pages = []
for title in page_titles:
page = pywikibot.Page(site, title)
if "rhyme list begin" not in page.text:
not_found_pages.append(title)
not_found_file_path = 'not_found_pages.txt'
with open(not_found_file_path, 'w', encoding='utf-8') as not_found_file:
for page_title in not_found_pages:
not_found_file.write(page_title + '\n')
print(f"The titles of the pages where the text was not found have been saved in '{not_found_file_path}'.")