Skip to content

Instantly share code, notes, and snippets.

@dharmatech
Last active August 14, 2023 00:41
Show Gist options
  • Save dharmatech/a19ca644b3a4a1fb0b340e9f0084c141 to your computer and use it in GitHub Desktop.
Save dharmatech/a19ca644b3a4a1fb0b340e9f0084c141 to your computer and use it in GitHub Desktop.

Rendering PowerShell terminal output as HTML

When I run this PowerShell script:

https://github.com/dharmatech/net-liquidity.ps1

the output looks as follows:

image

In order to share the results with others, I convert the output to HTML. The resulting page looks like this:

image

Here's a link to that page:

https://dharmatech.dev/data/reports/net-liquidity-table.html

Here's how the HTML is generated.

cron.sh

Here is cron.sh. It takes case of running the to-html.sh script inside screen (to provide a terminal to the underlying process):

#!/bin/sh

cd /var/www/dharmatech.dev/data/net-liquidity.ps1

screen -d -m ./to-html.sh

to-html.sh

Here is to-html.sh:

#!/bin/sh

cd /var/www/dharmatech.dev/data/net-liquidity.ps1

script -q -c 'pwsh -Command ./net-liquidity-earnings-remittances.ps1 -display_chart_url -save_iframe' script-out-nl

cat script-out-nl |
    /home/dharmatech/go/bin/terminal-to-html -preview |
    sed 's/pre-wrap/pre/' |
    sed 's/terminal-to-html Preview/Net Liquidity Table/' |
    sed 's/<body>/<body style="width: fit-content;">/' > ../reports/net-liquidity-table.html

mv net-liquidity-chart.html  ../reports
mv spx-fair-value-chart.html ../reports

It does the following:

crontab

This script is to run Mon-Fri at 10:20 eastern and 1:05 PM eastern. It should also run on Thur at 1:45 PM eastern. Here are the crontab entries for this:

20 10 * * MON-FRI /var/www/dharmatech.dev/data/net-liquidity.ps1/cron.sh
 5 13 * * MON-FRI /var/www/dharmatech.dev/data/net-liquidity.ps1/cron.sh
45 13 * * THU     /var/www/dharmatech.dev/data/net-liquidity.ps1/cron.sh

Video demonsration

Here's a short video walking through some of this.

https://twitter.com/dharmatrade/status/1690625000104140800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment