summaryrefslogtreecommitdiff
path: root/read.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2023-01-11 22:46:45 -0500
committercyfraeviolae <cyfraeviolae>2023-01-11 22:46:45 -0500
commit91759579d0fcd4acb48e7a209e8f79796fb67aaa (patch)
tree73e99ddc7914ec06902dce0ca5d0d4d68ef37eb9 /read.py
init
Diffstat (limited to 'read.py')
-rwxr-xr-xread.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/read.py b/read.py
new file mode 100755
index 0000000..4890d73
--- /dev/null
+++ b/read.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+from collections import defaultdict
+import pandas as pd
+
+columns = ['name', 'serving_size', 'calories', 'calories_from_fat', 'total_fat',
+ 'saturated_fat', 'trans_fat', 'cholesterol', 'sodium',
+ 'total_carbs', 'dietary_fiber', 'sugars', 'protein']
+bases = []
+signature_ingredients = []
+premium_ingredients = []
+dressings = []
+
+with open('out.csv') as fh:
+ lines = fh.readlines()
+
+tables = defaultdict(list)
+tablemap = {'BASES': 'Bases',
+ 'SIGNATURE INGREDIENTS': 'Signature ingredients',
+ 'PREMIUM INGREDIENTS': 'Premium ingredients',
+ '"DRESSINGS': 'Dressings'}
+title = None
+for line in lines:
+ line = line.strip()
+ if 'SIGNATURE MENU' in line:
+ break
+ if '(g)' in line:
+ title = line.split(',')[0]
+ continue
+ if title in tablemap:
+ cells = line.split(',')
+ cells = [cells[0]] + [int(cell) for cell in cells[1:]]
+ tables[tablemap[title]].append(cells)
+
+dfs = {name: pd.DataFrame(data=table, columns=columns) for name, table in tables.items()}
+
+import json
+jdfs = {name: df.to_dict('records') for name, df in dfs.items()}
+print('let data = ' + json.dumps(jdfs))