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.

61 lines
1.1 KiB
Python

2 years ago
import os
folder = "./images/"
#defining as a list
images = []
titles = []
#shows all the images
os.listdir(folder)
for image in os.listdir(folder):
print(image)
print(folder + image)
print("---")
images.append(folder + image)
titles.append(image)
#html
counter = 0
all_cards = ""
for image in images:
#html image element
img = f"<img src='{ image }'>"
#img = "<img src="' + image +"'>"
#define title
title = titles[counter]
#printing to inspect
print(img)
#mini template for card
card = f"""
<div class="card">
<h2>{ title }</h2>
<p>{ img }</p>
</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
counter = counter + 1
html = f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="stylesheet.css" rel="stylesheet">
</head>
<body>
<section>
{ all_cards }
</section>
</body>
</html>
"""
with open("cards.html", "w") as output:
output.write(html)