forked from dasmer/piatto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiatto.py
65 lines (44 loc) · 1.53 KB
/
piatto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
import csv
import io
from bs4 import BeautifulSoup
css = open('style.css').read()
csv = csv.DictReader(io.open(sys.argv[1], "r", encoding = "utf-8-sig"))
categories = []
rawItems = []
for item in csv:
rawItems.append(item)
category = item["item_category"]
if category not in categories:
categories.append(category)
list = dict()
for category in categories:
categoryItems = []
for item in rawItems:
itemCategory = item["item_category"]
if category == itemCategory:
categoryItems.append(item)
list[category] = categoryItems
html = "<style>" + css + "</style>"
html += "<div class=\"menu-body\">"
for category in categories:
items = list[category]
html+= "<div class=\"menu-section\"><h2 class=\"menu-section-title\">" + category + "</h2>"
for item in items:
description = item["item_description"]
if item["item_vegan"] == "TRUE":
description += "(Vegan)"
if item["item_glutenfree"] == "TRUE":
description += "(Gluten-Free)"
html += "<div class=\"menu-item\">"
html += "<div class=\"menu-item-name\">" + item["item_name"] + "</div>"
html += "<div class=\"menu-item-price\">$" + item["item_price"] + "</div>"
html += "<div class=\"menu-item-description\">" + description + "</div>"
html += "</div>"
html += "</div>"
html += "</div>"
soup = BeautifulSoup(html, "html.parser")
html = soup.prettify()
html_file = open(sys.argv[2], "w")
html_file.write(html)
html_file.close()