You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB
Python

import os , json
2 years ago
folder = "./images/"
#load the json information
with open ("cards.json", "r") as collage:
cards = json.load(collage)
2 years ago
#html
2 years ago
all_cards = ""
for card in cards["cards"]:
print(card)
2 years ago
#html image element
img = f"<img src='{ folder + card['image'] }'>"
2 years ago
#img = "<img src="' + image +"'>"
#define title
title = card['name']
2 years ago
#printing to inspect
print(img)
#mini template for card
if card['image'] == "":
card = f"""
<div class="card">
<h2>{ title }</h2>
<p class = 'textnoimage'>{ card['text'] }</p>
</div>
"""
else:
card = f"""
2 years ago
<div class="card">
<h2>{ title }</h2>
<p class = 'image'>{ img }</p>
<p class = 'text'>{ card['text'] }</p>
2 years ago
</div>
"""
#printing to inspect mini template
print(card)
#add it to the all cards variable
all_cards = all_cards + card
#we add +1 to our counter
html = f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>flex card</title>
<link href="stylesheet.css" rel="stylesheet">
</head>
<body>
<h1>cards</h1>
2 years ago
<section>
{ all_cards }
</section>
</body>
</html>
"""
with open("cards.html", "w") as output:
output.write(html)