#!/usr/bin/env python # -*- coding: utf-8 -*- # System packages import pathlib from pathlib import Path # Project package from htmlparser import DiscordHTMLParser path_project = pathlib.Path("/home/gmartin/Workspace/DiscordPrettyPrinter") if __name__ == '__main__': parser = DiscordHTMLParser(keep_time=False) folder_name = "sar" file_name = "mp" xml_path: pathlib.Path = path_project / "input" / folder_name / (file_name + ".xml") with open(xml_path, "r") as file_xml: xml_str = "" for line in file_xml: xml_str += line parser.feed(xml_str) # print(parser.export_messages()) print(f"Parsed: {xml_path}") print(f"{parser.nb_messages} messages found (and {parser.nb_duplicate} duplicates).") # Creation of the output folder if it does not exist. path_file_output: Path = ( path_project / "output" / folder_name / (file_name + ".html") ) path_file_output.parent.mkdir(parents=True, exist_ok=True) # Export of the parsed text and formatted into html. with open(path_file_output, "w") as file_htmloutput: file_htmloutput.write(parser.export_messages())