From 2c5b9d8fc46b71e0cdeae71a5e9ad146cf7e10ad Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:40:05 +0000 Subject: [PATCH 1/6] [Penify]: Documentation for commit - d98526e --- copy_to_en/medwiki.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/copy_to_en/medwiki.py b/copy_to_en/medwiki.py index 5fb63cf..4830415 100644 --- a/copy_to_en/medwiki.py +++ b/copy_to_en/medwiki.py @@ -71,6 +71,23 @@ def Create(title, text, summary): def get_text(x): + """Retrieve and process text from a specified page. + + This function fetches the text content of a page identified by the + parameter `x` using the `mdwiki_api.GetPageText` method. It processes + the retrieved text by searching for specific patterns, modifying + references, and ensuring that the output is formatted correctly. The + function also handles cases where the page may not contain any text, + returning an empty string in such instances. + + Args: + x (str): The identifier of the page from which to retrieve text. + + Returns: + str: The processed text content from the specified page. If no + text is found, an empty string is returned. + """ + alltext, revid = mdwiki_api.GetPageText(x, get_revid=True) # --- revids[x] = revid @@ -163,6 +180,16 @@ def start(all_pages): def main(): + """Main entry point for the application. + + This function orchestrates the workflow of the application by calling + various helper functions to retrieve and process data. It first gathers + a list of completed categories, then retrieves all available pages. If + the "nodone" argument is not provided, it filters out the completed + pages from the list of all pages. Finally, it initiates the processing + of the remaining pages and saves the revisions to a JSON file. + """ + # --- done = medwiki_cat_members() # --- From 2294475c8df872f8ae5a0073e24f4597a515e98c Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:40:06 +0000 Subject: [PATCH 2/6] [Penify]: Documentation for commit - d98526e --- md_core_helps/apis/mdwiki_api.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/md_core_helps/apis/mdwiki_api.py b/md_core_helps/apis/mdwiki_api.py index 20aa9ac..0e2bdbc 100644 --- a/md_core_helps/apis/mdwiki_api.py +++ b/md_core_helps/apis/mdwiki_api.py @@ -93,6 +93,25 @@ def wordcount(title, srlimit="30"): def GetPageText(title, redirects=False, get_revid=False): + """Retrieve the wikitext of a specified page from a wiki. + + This function sends a request to a wiki API to retrieve the wikitext of + a page identified by its title. It can handle redirects and can + optionally return the revision ID of the page. If the page does not + exist or cannot be parsed, appropriate messages are logged. + + Args: + title (str): The title of the page to retrieve. + redirects (bool?): Whether to follow redirects. Defaults to False. + get_revid (bool?): Whether to return the revision ID along with the wikitext. + Defaults to False. + + Returns: + str: The wikitext of the specified page. + tuple: A tuple containing the wikitext and the revision ID if get_revid is + True. + """ + # printe.output( '**GetarPageText: ') # --- params = { From 65847d4cdd1384142b2e1eeaaddc2cafb0619f29 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:40:06 +0000 Subject: [PATCH 3/6] [Penify]: Documentation for commit - d98526e --- td_core/after_translate/bots/add_to_wd.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/td_core/after_translate/bots/add_to_wd.py b/td_core/after_translate/bots/add_to_wd.py index bca7fe6..cc6dc88 100644 --- a/td_core/after_translate/bots/add_to_wd.py +++ b/td_core/after_translate/bots/add_to_wd.py @@ -98,6 +98,24 @@ def work_with_2_qids(oldq, new_q): def add_wd(qid, enlink, lang, target): + """Add a site link to a Wikidata item. + + This function adds a site link to a specified Wikidata item based on the + provided parameters. It constructs the necessary API request to link the + given target to either an existing item identified by `qid` or a new + item identified by `enlink`. The function handles both cases and checks + for potential conflicts with existing site links. + + Args: + qid (str): The unique identifier for the Wikidata item (QID). + enlink (str): The English link to the item if `qid` is not provided. + lang (str): The language code for the site link (e.g., 'ar' for Arabic). + target (str): The title of the site link to be added. + + Returns: + bool: True if the site link was successfully added, False otherwise. + """ + print("add_wd:") params = { "action": "wbsetsitelink", From eeecdd8b8d5ca097a3e50de5fa6554aebbf743dc Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:40:07 +0000 Subject: [PATCH 4/6] [Penify]: Documentation for commit - d98526e --- td_core/after_translate/mdwikicx.py | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/td_core/after_translate/mdwikicx.py b/td_core/after_translate/mdwikicx.py index 513f1a4..ce73385 100644 --- a/td_core/after_translate/mdwikicx.py +++ b/td_core/after_translate/mdwikicx.py @@ -23,6 +23,19 @@ def get_result(): + """Fetches the result from a specified URL and returns the rows of data. + + This function makes a GET request to a predefined URL to retrieve JSON + data. It extracts the "Rows" key from the JSON response and returns its + value. If an error occurs during the request or while processing the + response, the function catches the exception, prints an error message, + and returns an empty list. + + Returns: + list: A list of rows extracted from the JSON response. + If an error occurs, an empty list is returned. + """ + url = "https://hashtags.wmcloud.org/json/?query=mdwikicx" # --- try: @@ -38,6 +51,24 @@ def get_result(): def work_one_page(x): + """Process a single page based on the provided metadata. + + This function retrieves the QID associated with a given markdown title + and checks if the corresponding Wikipedia page exists. If the page + exists and is in the main namespace, it retrieves the QID of the page. + If the page does not exist or is not in the main namespace, appropriate + actions are taken, including logging output and potentially adding data + to Wikidata. + + Args: + x (dict): A dictionary containing metadata with keys "mdtitle", + "page_title", and "lang". + + Returns: + None: The function does not return a value but may perform side + effects such as logging output or modifying data. + """ + # --- qid = en_to_md.mdtitle_to_qid.get(x["mdtitle"], "") # --- @@ -65,6 +96,17 @@ def work_one_page(x): def main(): + """Main function to process command-line arguments and extract specific + information + from a predefined result list. This function iterates through command- + line arguments to check for a specified language option. It then + processes a hardcoded list of results, extracting relevant data such as + domain, timestamp, username, page title, and edit summary. The extracted + information is stored in a structured format and saved to a JSON file. + Additionally, the function filters out entries based on specific + usernames. + """ + # --- for arg in sys.argv: arg, _, value = arg.partition(":") From c75e27ca2032993f6a0496a48ccf25f96e0b0b3b Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:40:08 +0000 Subject: [PATCH 5/6] [Penify]: Documentation for commit - d98526e --- wprefs/bot1.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/wprefs/bot1.py b/wprefs/bot1.py index 0c2bb27..7d46a30 100644 --- a/wprefs/bot1.py +++ b/wprefs/bot1.py @@ -90,6 +90,24 @@ def one_page(page, lang): def one_file(file, lang): + """Process a file and apply transformations based on its content. + + This function reads the content of a specified file, applies a + transformation using the `fix_page_here` function, and saves the + modified content if changes are made. It handles file paths and ensures + that the file is read with UTF-8 encoding. If any errors occur during + file reading, they are caught and logged, and an empty string is + returned. The function also generates a random title for the transformed + content. + + Args: + file (str): The path to the input file. + lang (str): The language parameter used for transformation. + + Returns: + str: An empty string indicating the result of the operation. + """ + # --- text = "" # --- @@ -129,6 +147,18 @@ def one_file(file, lang): def maine(): + """Process command-line arguments and execute corresponding actions. + + This function parses command-line arguments to determine the desired + actions, such as loading a specific page or file, and setting the + language for processing. It checks for required parameters and invokes + the appropriate functions based on the provided arguments. If neither a + page nor a file is specified, it outputs an error message. + + Returns: + str: An empty string upon completion of processing. + """ + # --- page = "" lange = "" From 97369e77dbfc25107eec7ac60ec2d82a85b72130 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:40:08 +0000 Subject: [PATCH 6/6] [Penify]: Documentation for commit - d98526e --- wprefs/infobox.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wprefs/infobox.py b/wprefs/infobox.py index 5313a3b..410c9f7 100644 --- a/wprefs/infobox.py +++ b/wprefs/infobox.py @@ -44,6 +44,23 @@ def expend_new(main_temp): def Expend_Infobox(text, title, section_0): + """Expand the infobox in the provided text. + + This function processes the input text to expand an infobox based on the + specified title. It identifies sections within the text and modifies + them accordingly. If the section is empty, it attempts to extract + relevant information from the text. The function also handles template + extraction and ensures that the infobox is formatted correctly. + + Args: + text (str): The input text containing the infobox to be expanded. + title (str): The title of the infobox to be processed. + section_0 (str): An optional section of text that may contain relevant information. + + Returns: + str: The modified text with the expanded infobox. + """ + # --- newtext = text # ---