Skip to content

Commit

Permalink
Merge pull request #177 from MrIbrahem/penify/auto_doc_d98526e_da993
Browse files Browse the repository at this point in the history
[Penify]: Documentation for commit - d98526e
  • Loading branch information
MrIbrahem authored Sep 10, 2024
2 parents 73a1f45 + 97369e7 commit 068eaaf
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 0 deletions.
27 changes: 27 additions & 0 deletions copy_to_en/medwiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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
Expand Down Expand Up @@ -165,6 +182,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()
# ---
Expand Down
19 changes: 19 additions & 0 deletions md_core_helps/apis/mdwiki_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
18 changes: 18 additions & 0 deletions td_core/after_translate/bots/add_to_wd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 42 additions & 0 deletions td_core/after_translate/mdwikicx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"], "")
# ---
Expand Down Expand Up @@ -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(":")
Expand Down
30 changes: 30 additions & 0 deletions wprefs/bot1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
# ---
Expand Down Expand Up @@ -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 = ""
Expand Down
17 changes: 17 additions & 0 deletions wprefs/infobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---
Expand Down

0 comments on commit 068eaaf

Please sign in to comment.