Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
html-image-list.py | NOTE: Will be editing this script in the future to make it better
#!/usr/bin/python3
# ########################################################################### #
# HTML Image List #
# --------------- #
# Makes it easier to add images to an html file, by printing out all of the #
# names of all images in a directory, placed inside of a html link. (e.g. #
# Image name: "2018-11-20 2002.30.21.jpg" | output: "<a #
# href='2018-11-20%2002.30.21.jpg' target='_blank'><img #
# src='2018-11-20%2002.30.21.jpg' alt='2018-11-20 02.30.21.jpg' width=100% #
# height=100%></a>") #
# #
# Supported OS #
# ============ #
# * Linux #
# * macOS (or OS X) #
# ########################################################################### #
import os
where = input("What directory do we list? List full directory. ")
os.system("ls {} > html-list.txt".format(where))
with open("html-list.txt", "r") as txt:
for line in txt:
if line != " " or line != "":
line = line.rstrip("\r\n")
line_mod = line.replace(" ", "%20")
line_mod = line_mod.rstrip("\r\n")
print("<a href=\"{0}\" target=\"_blank\"><img src=\"{0}\" "
"alt=\"{1}\" width=100% height=100%></a>".format(line_mod, line))
os.system("rm html-list.txt")
@StrangeRanger

This comment has been minimized.

Copy link
Owner Author

@StrangeRanger StrangeRanger commented Jun 7, 2021

Project Tracker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment