use with to simplify the code
This commit is contained in:
		
							
								
								
									
										13
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								main.py
									
									
									
									
									
								
							@ -4,12 +4,11 @@ from Book import Book
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Opening JSON file
 | 
			
		||||
f = open('constructor.json', encoding='utf-8')
 | 
			
		||||
with open('constructor.json', encoding='utf-8') as f:
 | 
			
		||||
    data = json.load(f)
 | 
			
		||||
f.close()
 | 
			
		||||
f = open("style.css")
 | 
			
		||||
 | 
			
		||||
with open('style.css', encoding='utf-8') as f:
 | 
			
		||||
    style = f.read()
 | 
			
		||||
f.close()
 | 
			
		||||
 | 
			
		||||
books = data['books']
 | 
			
		||||
html = ""
 | 
			
		||||
@ -18,13 +17,11 @@ for book_data in books:
 | 
			
		||||
    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()
 | 
			
		||||
 | 
			
		||||
f = open("cast.html")
 | 
			
		||||
with open('cast.html', encoding='utf-8') as f:
 | 
			
		||||
    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')
 | 
			
		||||
    with open(sys.argv[1], "w", encoding='utf-8') as f:
 | 
			
		||||
        f.write(text)
 | 
			
		||||
    f.close()
 | 
			
		||||
else:
 | 
			
		||||
    print(text)
 | 
			
		||||
		Reference in New Issue
	
	Block a user