#! /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)