Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GT.save() #454

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def save(
web_driver: WebDrivers = "chrome",
window_size: tuple[int, int] = (6000, 6000),
debug_port: None | int = None,
encoding: str = "utf-8",
_debug_dump: DebugDumpOptions | None = None,
) -> None:
"""
Expand Down Expand Up @@ -215,6 +216,8 @@ def save(
to capture a table, but may affect the tables appearance.
debug_port
Port number to use for debugging. By default no debugging port is opened.
encoding
The encoding used when writing temporary files.
_debug_dump
Whether the saved image should be a big browser window, with key elements outlined. This is
helpful for debugging this function's resizing, cropping heuristics. This is an internal
Expand Down Expand Up @@ -255,11 +258,8 @@ def save(
if selector != "table":
raise NotImplementedError("Currently, only selector='table' is supported.")

# Get the file extension from the file name
file_extension = file.split(".")[-1]

# If there is no file extension, add the .png extension
if len(file_extension) == len(file):
if not Path(file).suffix:
file += ".png"

# Get the HTML content from the displayed output
Expand Down Expand Up @@ -306,11 +306,11 @@ def save(
):

# Write the HTML content to the temp file
with open(f"{tmp_dir}/table.html", "w") as temp_file:
with open(f"{tmp_dir}/table.html", "w", encoding=encoding) as temp_file:
temp_file.write(html_content)

# Open the HTML file in the headless browser
headless_browser.set_window_size(window_size[0], window_size[1])
headless_browser.set_window_size(*window_size)
headless_browser.get("file://" + temp_file.name)

_save_screenshot(headless_browser, scale, file, debug=_debug_dump)
Expand Down