User:Şêr/kunounforms.py

From Wiktionary, the free dictionary
Jump to navigation Jump to search
import pywikibot

def create_pages_from_file(file_name):
    # Connect to the English Wiktionary
    site = pywikibot.Site('en', 'wiktionary')

    # Open the text file and read page titles
    with open(file_name, 'r', encoding='utf-8') as file:
        page_titles_list = file.readlines()
    
    for page_title in page_titles_list:
        # Clean up page title
        page_title = page_title.strip()

        # Create the page if it doesn't exist
        page = pywikibot.Page(site, page_title)
        if not page.exists():
            # Create page content
            page_content = f"==Northern Kurdish==\n\n===Noun===\n{{{{head|kmr|noun form|g=f}}}}\n\n# {{{{infl of|kmr|page_title||def|cons|p}}}}"

            # Set page content and save
            page.text = page_content
            page.save(summary=f'Testpage {page_title} (for bot request: [[:Wiktionary:Votes/bt-2024-02/User:JiyanBot for bot status]]) has been created.')

if __name__ == '__main__':
    # Specify the file name containing the page titles
    file_name = 'test.txt'
    create_pages_from_file(file_name)