MyReadings/main.py

27 lines
721 B
Python
Raw Permalink Normal View History

2024-08-05 15:14:49 -04:00
import json
2024-08-06 06:56:44 -04:00
import sys
2024-08-05 15:14:49 -04:00
from Book import Book
2024-08-06 06:56:44 -04:00
2024-08-05 15:14:49 -04:00
# Opening JSON file
2024-08-06 08:49:58 -04:00
with open('constructor.json', encoding='utf-8') as f:
data = json.load(f)
with open('style.css', encoding='utf-8') as f:
style = f.read()
2024-08-05 15:14:49 -04:00
books = data['books']
html = ""
for book_data in books:
2024-08-06 08:45:37 -04:00
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"])
2024-08-05 15:14:49 -04:00
html += book.to_html()
2024-08-06 08:49:58 -04:00
with open('cast.html', encoding='utf-8') as f:
text = f.read().replace("{{books}}", html).replace("{{style}}", style)
2024-08-06 06:56:44 -04:00
if len(sys.argv) > 1:
2024-08-06 08:49:58 -04:00
with open(sys.argv[1], "w", encoding='utf-8') as f:
f.write(text)
2024-08-06 06:56:44 -04:00
else:
print(text)