-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite_generator.py
48 lines (40 loc) · 1.65 KB
/
website_generator.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
import csv
from jinja2 import Template
from dataclasses import dataclass
@dataclass
class Musette(dict):
team: str
year: str
category: str
picture_front: str
picture_back: str
difference: str
kevin: str
special: str
url_front: str
url_back: str
class InventoryGenerator:
def __init__(self):
self.file_name = "inventory_new.csv"
self.musettes_list = []
def import_csv(self):
with open(self.file_name, newline='', errors="ignore") as csvfile:
musettes_list = csv.reader(csvfile, delimiter=';', quotechar='|')
for team, year, category, picture_front, picture_back, difference, kevin, special, url_front, url_back in musettes_list:
if url_front != "" and not url_front.startswith("http"):
url_front = "images/" + url_front + ".png"
if url_back != "" and not url_back.startswith("http"):
url_back = "images/" + url_back + ".png"
mus = Musette(team, year, category, picture_front, picture_back, difference, kevin, special, url_front, url_back)
self.musettes_list.append(mus)
def generate_website(self):
with open("website_template.html.j2", newline='') as jinja_template:
website_template = jinja_template.read()
website_html = Template(source=website_template).render(musette_list=self.musettes_list)
print(website_html)
with open("index.html", "w") as text_file:
text_file.write(website_html)
if __name__ == '__main__':
generator = InventoryGenerator()
generator.import_csv()
generator.generate_website()