Compare commits
4 Commits
2ca297e68c
...
master
Author | SHA1 | Date | |
---|---|---|---|
a5ceb76e43 | |||
e26fced271 | |||
007811bde6 | |||
5177238a53 |
4
Book.py
4
Book.py
@ -1,18 +1,20 @@
|
|||||||
class Book:
|
class Book:
|
||||||
|
|
||||||
def __init__(self, name: str, description: str, image: str, review: str, release_date: str, reading_date: str) -> None:
|
def __init__(self, name: str, author: str, description: str, image: str, review: str, release_date: str, reading_date: str) -> None:
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
self.description: str = description
|
self.description: str = description
|
||||||
self.image: str = image
|
self.image: str = image
|
||||||
self.review: str = review
|
self.review: str = review
|
||||||
self.release_date: str = release_date
|
self.release_date: str = release_date
|
||||||
self.reading_date: str = reading_date
|
self.reading_date: str = reading_date
|
||||||
|
self.author: str = author
|
||||||
|
|
||||||
def to_html(self) -> str:
|
def to_html(self) -> str:
|
||||||
return f"""
|
return f"""
|
||||||
<tr>
|
<tr>
|
||||||
<td class="image-div"><img src="img/{self.image}"></td>
|
<td class="image-div"><img src="img/{self.image}"></td>
|
||||||
<td class="namedesc-div">
|
<td class="namedesc-div">
|
||||||
|
<p class="author">{self.author}</p>
|
||||||
<p class="name">{self.name}</p>
|
<p class="name">{self.name}</p>
|
||||||
<p class="description">{self.description}</p>
|
<p class="description">{self.description}</p>
|
||||||
<p class="release-date">{self.release_date}</p>
|
<p class="release-date">{self.release_date}</p>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
A script to generate a static book review page
|
A script to generate a static book review page
|
||||||
|
|
||||||
## images
|
## images
|
||||||
|

|
||||||
## usage
|
## usage
|
||||||
|
|
||||||
- fill the  like the 
|
- fill the  like the 
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"books": [
|
"books": [
|
||||||
{
|
{
|
||||||
"name": "1984",
|
"name": "1984",
|
||||||
|
"author": "George Orwell",
|
||||||
"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",
|
"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",
|
"image": "1984.jpg",
|
||||||
"review": "ct pas mal",
|
"review": "ct pas mal",
|
||||||
|
21
main.py
21
main.py
@ -4,27 +4,24 @@ from Book import Book
|
|||||||
|
|
||||||
|
|
||||||
# Opening JSON file
|
# Opening JSON file
|
||||||
f = open('constructor.json', encoding='utf-8')
|
with open('constructor.json', encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
f.close()
|
|
||||||
f = open("style.css")
|
with open('style.css', encoding='utf-8') as f:
|
||||||
style = f.read()
|
style = f.read()
|
||||||
f.close()
|
|
||||||
|
|
||||||
books = data['books']
|
books = data['books']
|
||||||
html = ""
|
html = ""
|
||||||
|
|
||||||
for book_data in books:
|
for book_data in books:
|
||||||
book = Book(book_data["name"], book_data["description"], book_data["image"], book_data["review"], book_data["release_date"], book_data["reading_date"])
|
book = Book(book_data["name"], book_data["author"], book_data["description"], book_data["image"], book_data["review"], book_data["release_date"], book_data["reading_date"])
|
||||||
html += book.to_html()
|
html += book.to_html()
|
||||||
|
|
||||||
f = open("cast.html")
|
with open('cast.html', encoding='utf-8') as f:
|
||||||
text = f.read().replace("{{books}}", html).replace("{{style}}", style)
|
text = f.read().replace("{{books}}", html).replace("{{style}}", style)
|
||||||
f.close()
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
f = open(sys.argv[1], "w", encoding='utf-8')
|
with open(sys.argv[1], "w", encoding='utf-8') as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
f.close()
|
|
||||||
else:
|
else:
|
||||||
print(text)
|
print(text)
|
BIN
screenshots/1.png
Normal file
BIN
screenshots/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 329 KiB |
Reference in New Issue
Block a user