From 9934dd538b0ce116e3b1600272cb46369b082246 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 2 Feb 2022 13:34:47 +0800 Subject: init commit --- www/scripts/add-graph.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 www/scripts/add-graph.py (limited to 'www/scripts/add-graph.py') diff --git a/www/scripts/add-graph.py b/www/scripts/add-graph.py new file mode 100755 index 0000000..455b45a --- /dev/null +++ b/www/scripts/add-graph.py @@ -0,0 +1,35 @@ +#! /bin/python3 + +import sys, subprocess +from datetime import date +from bs4 import BeautifulSoup + +def handle(html): + soup = BeautifulSoup(html, 'html.parser') + for graph in soup.select('pre.language-graph'): + print() + print(date.today().strftime("%H:%M:%S")) + print('before:') + print(graph.string) + + process = subprocess.Popen( + ["/usr/bin/vendor_perl/graph-easy", "--boxart"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + output, error = process.communicate(input=graph.get_text().encode()) + graph.string = output.decode() + + print('After:') + print(graph.string) + print('Error:') + print(error.decode()) + return str(soup) + +for line in sys.stdin: + file = line.rstrip("\n") + with open(file, 'r') as html: + new_content = handle(html) + with open(file, 'w') as html: + html.write(new_content) -- cgit v1.2.3-70-g09d2