Skip to content

Commit

Permalink
print exports to terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshdsk committed Oct 16, 2021
1 parent 8943924 commit 5dddadb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions examples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,37 @@ def print_table():
table.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889")
table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889")

console.print(table, justify="center")
console.print(table)


# Prints table
print_table()

# Get console output as text
file1 = "table_export_plaintext.txt"
text = console.export_text()
with open("plaintext_export.txt", "w") as file:
with open(file1, "w") as file:
file.write(text)
print(f"Exported console output as plain text to {file1}")

# Calling print_table again because console output buffer
# is flushed once export function is called
print_table()

# Get console output as html
# use clear=False so output is not flushed after export
file2 = "table_export_html.html"
html = console.export_html(clear=False)
with open("html_export.html", "w") as file:
with open(file2, "w") as file:
file.write(html)
print(f"Exported console output as html to {file2}")

# Export text output to table_export.txt
console.save_text("rich_export.txt", clear=False)
file3 = "table_export_plaintext2.txt"
console.save_text(file3, clear=False)
print(f"Exported console output as plain text to {file3}")

# Export html output to table_export.html
console.save_html("rich_export.html")
file4 = "table_export_html2.html"
console.save_html(file4)
print(f"Exported console output as html to {file4}")

0 comments on commit 5dddadb

Please sign in to comment.