From 5a8833d465d04583b66e94d0854c766ff3477cc8 Mon Sep 17 00:00:00 2001 From: starnakin Date: Mon, 5 Aug 2024 21:14:49 +0200 Subject: [PATCH] init --- .gitignore | 3 +++ Book.py | 17 +++++++++++++++++ cast.html | 12 ++++++++++++ constructor.json | 4 ++++ constructor_example.json | 10 ++++++++++ main.py | 20 ++++++++++++++++++++ 6 files changed, 66 insertions(+) create mode 100644 .gitignore create mode 100644 Book.py create mode 100644 cast.html create mode 100644 constructor.json create mode 100644 constructor_example.json create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1a48d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +__pycache__ +site \ No newline at end of file diff --git a/Book.py b/Book.py new file mode 100644 index 0000000..15f03e6 --- /dev/null +++ b/Book.py @@ -0,0 +1,17 @@ +class Book: + + def __init__(self, name: str, description: str, image: str, review: str) -> None: + self.name: str = name + self.description: str = description + self.image: str = image + self.review: str = review + + def to_html(self) -> str: + return f""" + + {self.name} + {self.description} + img/{self.image} + {self.review} + + """ \ No newline at end of file diff --git a/cast.html b/cast.html new file mode 100644 index 0000000..d76a1f2 --- /dev/null +++ b/cast.html @@ -0,0 +1,12 @@ + + + + My Readings + + + +

My Readings

+ + {{}} +
+ \ No newline at end of file diff --git a/constructor.json b/constructor.json new file mode 100644 index 0000000..521571e --- /dev/null +++ b/constructor.json @@ -0,0 +1,4 @@ +{ + "books": [ + ] +} \ No newline at end of file diff --git a/constructor_example.json b/constructor_example.json new file mode 100644 index 0000000..51b7a86 --- /dev/null +++ b/constructor_example.json @@ -0,0 +1,10 @@ +{ + "books": [ + { + "name": "1984", + "description": "1984 est un roman dystopique de l'écrivain britannique George Orwell. Publié le 8 juin 1949 par Secker & Warburg, il s'agit du neuvième et dernier livre d'Orwell achevé de son vivant", + "image": "1984.jpg", + "review": "ct pas mal" + } + ] +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..07894ab --- /dev/null +++ b/main.py @@ -0,0 +1,20 @@ +import json +from Book import Book + +# Opening JSON file +f = open('constructor.json') + +data = json.load(f) + +f.close() + +books = data['books'] +html = "" + +for book_data in books: + book = Book(book_data["name"], book_data["description"], book_data["image"], book_data["review"]) + html += book.to_html() + +f = open("cast.html") +print(f.read().replace("{{}}", html)) +f.close() \ No newline at end of file