try: import re from pandas import DataFrame from typing import Union from logging import debug as dbg, getLogger import win32clipboard def create_table(xmlStr: str) -> Union[DataFrame, Exception]: dataDict = { "SEQ": [], } MATCH_SCENARIO = "((?!((?!" c = list(re.finditer(CONDITION_REGEX,senarioGroup)) dbg(f"conditions:\n{[cond for cond in c]}") senarioDict = {} senarioDict["SEQ"] = int(seq) for m in c: group = m.group() idStart, idEnd = re.search("\"[^\"]*\"", group).span() id = group[idStart+1:idEnd-1] dbg(f"SEQ: {seq} | {id}") valueGroup = re.search("e\">(.)*<", group) if valueGroup == None: valueGroup = re.search("e\"(((?! str: correct = False while not correct: win32clipboard.OpenClipboard() try: xml = win32clipboard.GetClipboardData() except: xml = "None" win32clipboard.CloseClipboard() print(f"\n\nYour current clipboard is as follows:") print(xml) yn = input("\nIs this the XML you'd like to parse? (y/n)\n >") if yn.lower() == "debug": getLogger().setLevel(10) print("\nYou have now entered debug mode...") correct = True if re.search("(?i)y|1", yn) != None else False if not correct: input("Please copy the xml then press enter...") return xml table = None while type(table) != DataFrame: xml = process_clipboard() table: Union[DataFrame, Exception] = create_table(xml) if type(table) != DataFrame: print(f"\n\nENCOUNTERED ERROR!:\n{table}\n") input("Please try again...") continue print(f"Table sample:") print(table) table.to_clipboard() input("This table is now in your clipboard to paste into excel.") except Exception as e: print(f"The program failed to start do the the following exception:\n{e}") input(f"Please make note of the error before closing so that you can report it.")