import pywikibot
def add_minitoc(page_title):
site = pywikibot.Site('en', 'wiktionary')
page = pywikibot.Page(site, page_title)
if not page.exists():
print(f"Page '{page_title}' does not exist.")
return
text = page.text
lines = text.splitlines()
insert_index = None
for i, line in enumerate(lines):
if line.startswith('=='):
insert_index = i
break
if insert_index is not None:
lines.insert(insert_index, "{{minitoc}}")
new_text = '\n'.join(lines)
if new_text != page.text:
page.text = new_text
page.save("Added {{minitoc}}")
else:
print(f"No changes needed for '{page_title}'.")
else:
print(f"No section headings found in '{page_title}'.")
if __name__ == "__main__":
page_list = ["Page 1", "Page 2", "Page 3"] # Replace with your actual list of page titles
for page_title in page_list:
add_minitoc(page_title)