Skip to content

Commit

Permalink
Release v0.0.2
Browse files Browse the repository at this point in the history
Include an option to return raw HTML data
  • Loading branch information
dormant-user committed Nov 25, 2024
1 parent 5b6d518 commit b7fcc6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyudisk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .main import generate_report, monitor

version = "0.0.1"
version = "0.0.2"


@click.command()
Expand Down
11 changes: 7 additions & 4 deletions pyudisk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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


Expand All @@ -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"
Expand Down

0 comments on commit b7fcc6e

Please sign in to comment.