48 lines
1.1 KiB
Python
Executable File
48 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import csv
|
|
import dataclasses
|
|
import requests
|
|
|
|
backend = 'http://localhost:8000'
|
|
products_file = './product_definitions.csv'
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class Tikette:
|
|
category: str
|
|
designation: str
|
|
ingredients: str
|
|
description: str
|
|
color: str
|
|
svg: str
|
|
ab: str
|
|
|
|
def newtikette_payload(self, katzids):
|
|
return {
|
|
'title': self.svg.split('.')[0],
|
|
'category_id': katzids[self.category],
|
|
'designation': self.designation,
|
|
'ingredients': self.ingredients,
|
|
'description': self.description,
|
|
'color': self.color,
|
|
'ab': 'inline' if self.ab else 'none',
|
|
}
|
|
|
|
|
|
def get_tikettes():
|
|
with open('./product_definitions.csv') as f:
|
|
return [Tikette(*x) for x in csv.reader(f, delimiter=';')]
|
|
|
|
|
|
def populate_database():
|
|
katz = requests.get(backend + '/categories', json=True).json()['tikats']
|
|
katzids = {x['name'].lower(): x['id'] for x in katz}
|
|
|
|
for tk in get_tikettes():
|
|
requests.post(backend + '/newtikette', json=tk.newtikette_payload(katzids))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
populate_database()
|