diff options
Diffstat (limited to 'www/scripts/add-graph.py')
-rwxr-xr-x | www/scripts/add-graph.py | 35 |
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 | |||
3 | import sys, subprocess | ||
4 | from datetime import date | ||
5 | from bs4 import BeautifulSoup | ||
6 | |||
7 | def 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 | |||
30 | for 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) | ||