Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import sys
import os
import csv
import json
import string

template = '''
<html>
<head>
<title>Will it scale?</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdn.plot.ly/plotly-3.1.0.min.js" charset="utf-8"></script>
<script src="plot.js"></script>
</head>

Expand Down Expand Up @@ -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__':

Expand Down