From 91759579d0fcd4acb48e7a209e8f79796fb67aaa Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Wed, 11 Jan 2023 22:46:45 -0500 Subject: init --- read.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 read.py (limited to 'read.py') 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)) -- cgit v1.2.3