write to file bruh

This commit is contained in:
2024-06-26 15:24:22 +02:00
committed by Flo Greistorfer
parent 623a08d1d4
commit 1f7dad2a87

View File

@@ -15,20 +15,39 @@ rawext = [".ARW", ".tif", ".tiff", ".TIF", ".TIFF"]
def listfolder(folder: str): def listfolder(folder: str):
items: list[str] = os.listdir(folder) items: list[str] = os.listdir(folder)
items.sort() items.sort()
for item in items: images: list[str] = []
if item != "Galleries" and item != ".previews": subfolders: list[str] = []
if os.path.isdir(os.path.join(folder, item)):
print(f'<b><a href="{webroot}{folder.removeprefix(root)}/{item}">{item}</a></b><br>') if not os.path.exists(os.path.join(root, ".previews", folder.removeprefix(root))):
listfolder(os.path.join(folder, item)) os.mkdir(os.path.join(root, ".previews", folder.removeprefix(root)))
else:
if os.path.splitext(item)[1] in imgext: with open(os.path.join(folder, "list.txt"), "w", encoding="utf-8") as f:
print(f'<img href="{webroot}{folder.removeprefix(root)}/{item}">{item}</img><br>') for item in items:
for raw in rawext: if item != "Galleries" and item != ".previews":
if os.path.exists(os.path.join(folder, os.path.splitext(item)[0] + raw)): if os.path.isdir(os.path.join(folder, item)):
print(f'<a href="{webroot}{folder.removeprefix(root)}/{os.path.splitext(item)[0]}{raw}">RAW</a><br>') subfolders.extend([f'<b><a href="{webroot}{folder.removeprefix(root)}/{item}">{item}</a></b><br>'])
listfolder(os.path.join(folder, item))
else:
if os.path.splitext(item)[1] in imgext:
images.extend([f'<img href="{webroot}{folder.removeprefix(root)}/{item}">{item}</img><br>'])
if not os.path.exists(os.path.join(root, ".previews", folder.removeprefix(root), item)):
# os.system(f'magick {os.path.join(folder, item)} -resize 1024x768! {os.path.join(root, ".previews", folder.removeprefix(root), item)}')
print(f'magick {os.path.join(folder, item)} -resize 1024x768! {os.path.join(root, ".previews", folder.removeprefix(root), item)}')
for raw in rawext:
if os.path.exists(os.path.join(folder, os.path.splitext(item)[0] + raw)):
images.extend([f'<a href="{webroot}{folder.removeprefix(root)}/{os.path.splitext(item)[0]}{raw}">RAW</a><br>'])
for image in images:
f.write(image)
f.write("\n")
for subfolder in subfolders:
f.write(subfolder)
f.write("\n")
f.close()
def main(): def main():
global root
global webroot
if not root.endswith("/"): if not root.endswith("/"):
root += "/" root += "/"
if not webroot.endswith("/"): if not webroot.endswith("/"):
@@ -36,5 +55,6 @@ def main():
listfolder(root) listfolder(root)
# @TODO: write actual html files (and css 🙄) # @TODO: write actual html files (and css 🙄)
if __name__ == "__main__": if __name__ == "__main__":
main() main()