From 5612d838f33744be100f88679a94c560ca277bdb Mon Sep 17 00:00:00 2001 From: Shivank Garg Date: Tue, 19 Aug 2025 08:28:30 +0000 Subject: [PATCH] postprocess: fix plotly CDN and improve data handling Fix plotly-latest.min.js deprecation error causing resource load failures. Update to plotly-3.1.0.min.js and add JSON serialization for proper data formatting. - Update plotly CDN to supported version - Add json import and convert CSV data to JSON - Improve error handling and file operations - Remove unused for_each_file function Signed-off-by: Shivank Garg --- postprocess.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/postprocess.py b/postprocess.py index 98b2a5f..b011699 100755 --- a/postprocess.py +++ b/postprocess.py @@ -3,13 +3,14 @@ import sys import os import csv +import json import string template = ''' Will it scale? - + @@ -38,21 +39,26 @@ def process(base): titlefile = base + '.title' htmlfile = base + '.html' - data = parse_data(csvfile) - title = open(titlefile).readline().strip() + try: + data = parse_data(csvfile) + try: + with open(titlefile, 'r') as f: + title = f.readline().strip() + except FileNotFoundError: + title = f"Chart for {base}" + print(f"Warning: {titlefile} not found, using default title") - t = string.Template(template) - html = t.substitute(data=data, title=title) + json_data = json.dumps(data) + t = string.Template(template) + html = t.substitute(data=json_data, title=title) - open(htmlfile, 'w').write(html) - print('Created %s' % (htmlfile)) - - -def for_each_file(dirname, subdirs, filenames): - for f in filenames: - if f.endswith('.csv'): - process(f) + with open(htmlfile, 'w') as f: + f.write(html) + print(f'Created {htmlfile}') + except Exception as e: + print(f"Error processing {base}: {e}") + return False if __name__ == '__main__':