From b7fcc6e3031b8051a6776a8c98c2fc839027ca71 Mon Sep 17 00:00:00 2001 From: dormant-user Date: Mon, 25 Nov 2024 11:57:22 -0600 Subject: [PATCH] Release `v0.0.2` Include an option to return raw HTML data --- pyudisk/__init__.py | 2 +- pyudisk/main.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyudisk/__init__.py b/pyudisk/__init__.py index 84a24f8..bd7116c 100644 --- a/pyudisk/__init__.py +++ b/pyudisk/__init__.py @@ -7,7 +7,7 @@ from .main import generate_report, monitor -version = "0.0.1" +version = "0.0.2" @click.command() diff --git a/pyudisk/main.py b/pyudisk/main.py index c4a138c..b8d7da9 100644 --- a/pyudisk/main.py +++ b/pyudisk/main.py @@ -246,7 +246,7 @@ def monitor_disk(env: EnvConfig) -> Generator[Disk]: def generate_html( - data: List[Dict[str, str | int | float | bool]], filepath: NewPath + data: List[Dict[str, str | int | float | bool]], filepath: NewPath = None ) -> str: """Generates an HTML report using Jinja2 template. @@ -265,9 +265,10 @@ def generate_html( html_output = template.render( data=data, last_updated=f"{now.strftime('%c')} {now.astimezone().tzinfo}" ) - with open(filepath, "w") as file: - file.write(html_output) - file.flush() + if filepath: + with open(filepath, "w") as file: + file.write(html_output) + file.flush() return html_output @@ -282,6 +283,8 @@ def generate_report(**kwargs) -> str: Returns the report filepath. """ env = EnvConfig(**kwargs) + if kwargs.get("raw"): + return generate_html([disk.model_dump() for disk in monitor_disk(env)]) if report_file := kwargs.get("filepath"): assert report_file.endswith( ".html"