ALDashboard.docx_wrangling
update_docx
def update_docx(
        document: Union[docx.document.Document, str],
        modified_runs: List[Tuple[int, int, str,
                                  int]]) -> docx.document.Document
Update the document with modified runs.
Arguments
- document- the docx.Document object, or the path to the DOCX file
- modified_runs- a tuple of paragraph number, run number, the modified text, and a number from -1 to 1 indicating whether a new paragraph should be inserted before or after the current paragraph.
Returns
The modified document.
get_labeled_docx_runs
def get_labeled_docx_runs(
        docx_path: str,
        custom_people_names: Optional[Tuple[str, str]] = None,
        openai_client: Optional[OpenAI] = None
) -> List[Tuple[int, int, str, int]]
Scan the DOCX and return a list of modified text with Jinja2 variable names inserted.
Arguments
- docx_path- path to the DOCX file
- custom_people_names- a tuple of custom names and descriptions to use in addition to the default ones. Like: ("clients", "the person benefiting from the form")
Returns
A list of tuples, each containing a paragraph number, run number, and the modified text of the run.
modify_docx_with_openai_guesses
def modify_docx_with_openai_guesses(docx_path: str) -> docx.document.Document
Uses OpenAI to guess the variable names for a document and then modifies the document with the guesses.
Arguments
- docx_pathstr - Path to the DOCX file to modify.
Returns
- docx.Document- The modified document, ready to be saved to the same or a new path