summaryrefslogtreecommitdiffhomepage
path: root/www/scripts/add-graph.py
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2022-02-02 13:34:47 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-11-30 21:09:29 +0800
commit9934dd538b0ce116e3b1600272cb46369b082246 (patch)
tree2f28c6c362201151eaf8218e566479ed7eb72070 /www/scripts/add-graph.py
init commit
Diffstat (limited to 'www/scripts/add-graph.py')
-rwxr-xr-xwww/scripts/add-graph.py35
1 files changed, 35 insertions, 0 deletions
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 @@
1#! /bin/python3
2
3import sys, subprocess
4from datetime import date
5from bs4 import BeautifulSoup
6
7def handle(html):
8 soup = BeautifulSoup(html, 'html.parser')
9 for graph in soup.select('pre.language-graph'):
10 print()
11 print(date.today().strftime("%H:%M:%S"))
12 print('before:')
13 print(graph.string)
14
15 process = subprocess.Popen(
16 ["/usr/bin/vendor_perl/graph-easy", "--boxart"],
17 stdin=subprocess.PIPE,
18 stdout=subprocess.PIPE,
19 stderr=subprocess.PIPE
20 )
21 output, error = process.communicate(input=graph.get_text().encode())
22 graph.string = output.decode()
23
24 print('After:')
25 print(graph.string)
26 print('Error:')
27 print(error.decode())
28 return str(soup)
29
30for line in sys.stdin:
31 file = line.rstrip("\n")
32 with open(file, 'r') as html:
33 new_content = handle(html)
34 with open(file, 'w') as html:
35 html.write(new_content)