30 lines
609 B
Python
30 lines
609 B
Python
import json
|
|
import sys
|
|
from Book import Book
|
|
|
|
|
|
# Opening JSON file
|
|
f = open('constructor.json', encoding='utf-8')
|
|
data = json.load(f)
|
|
f.close()
|
|
f = open("style.css")
|
|
style = f.read()
|
|
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")
|
|
text = f.read().replace("{{books}}", html).replace("{{style}}", style)
|
|
f.close()
|
|
|
|
if len(sys.argv) > 1:
|
|
f = open(sys.argv[1], "w", encoding='utf-8')
|
|
f.write(text)
|
|
f.close()
|
|
else:
|
|
print(text) |