weiter gemacht
This commit is contained in:
parent
1831e2393f
commit
c4f990ea0c
148
purrpic.py
148
purrpic.py
|
|
@ -12,10 +12,17 @@ from PIL import Image
|
||||||
import argparse
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import datetime
|
||||||
|
|
||||||
BUILD_DIR = Path("./build")
|
BUILD_DIR = Path("./build")
|
||||||
CONF_DIR = Path("./conf")
|
CONF_DIR = Path("./conf")
|
||||||
|
THUMBSIZE = (300, 300)
|
||||||
|
GLOBALNAME = "Chrissys random Imagelibrary"
|
||||||
|
AUTHOR = "Luzia Christiane Tesar"
|
||||||
|
LANGUAGE = "en"
|
||||||
|
DESCRIPTION = ""
|
||||||
|
TODAY = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||||
|
CANONICALURL = "https://dm2lct.radio"
|
||||||
|
|
||||||
class HTML:
|
class HTML:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|
@ -23,21 +30,88 @@ class HTML:
|
||||||
self.footer = Path(CONF_DIR / "footer.html").read_text()
|
self.footer = Path(CONF_DIR / "footer.html").read_text()
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
print(self.outfolder)
|
|
||||||
print(BUILD_DIR)
|
|
||||||
|
|
||||||
def setTitle(self, title):
|
def title(self, title):
|
||||||
return f"""<h1>{title}</h1>\n"""
|
return f"""<h1>{title}</h1>\n"""
|
||||||
|
|
||||||
def div(self, divclass, data):
|
def par(self, text):
|
||||||
return f"""<div class="{divclass}">{data}</div>\n"""
|
return f"""<p>{text}</p>\n"""
|
||||||
|
|
||||||
def postImage(self, src, alt=None, width=None, title=None):
|
def div(self, divclass):
|
||||||
|
return f"""<div class="{divclass}">\n"""
|
||||||
|
|
||||||
|
def endDiv(self):
|
||||||
|
return f"""</div>\n"""
|
||||||
|
|
||||||
|
def img(self, src, alt=None, width=None, title=None):
|
||||||
return f"""<img src="{src}" alt="{alt}" title="{title}" />\n"""
|
return f"""<img src="{src}" alt="{alt}" title="{title}" />\n"""
|
||||||
|
|
||||||
|
def aimg(self, src, dest, alt=None, width=None, title=None):
|
||||||
|
return f"""<a href = "{dest}"><img src="{src}" alt="{alt}" title="{title}"/></a>\n"""
|
||||||
|
|
||||||
def link(self, dest, data):
|
def link(self, dest, data):
|
||||||
return f"""<a href="{dest}">{data}</a>"""
|
return f"""<a href="{dest}">{data}</a>"""
|
||||||
|
|
||||||
|
def headermeta(self, title):
|
||||||
|
header = self.header.replace("{{title}}", title)
|
||||||
|
header = header.replace("{{cannonical_url}}", CANONICALURL)
|
||||||
|
header = header.replace("{{global_name}}", GLOBALNAME)
|
||||||
|
header = header.replace("{{global_name}}", GLOBALNAME)
|
||||||
|
header = header.replace("{{author}}", AUTHOR)
|
||||||
|
header = header.replace("{{language}}", LANGUAGE)
|
||||||
|
header = header.replace("{{description}}", DESCRIPTION)
|
||||||
|
header = header.replace("{{published_date}}", TODAY)
|
||||||
|
return header
|
||||||
|
|
||||||
|
def writeIndex(self, indir, odir, title):
|
||||||
|
with open(f"{odir}/index.html", "w", encoding="utf-8") as file:
|
||||||
|
breakpoint()
|
||||||
|
file.write(self.headermeta(title))
|
||||||
|
file.write(self.title(title))
|
||||||
|
file.write(self.div("row"))
|
||||||
|
imglist = glob.glob(str(odir) + "/.thumbnails/*")
|
||||||
|
for n in range(0,3):
|
||||||
|
file.write(self.div("column"))
|
||||||
|
for i in range(n, len(imglist),3):
|
||||||
|
file.write(
|
||||||
|
self.aimg(
|
||||||
|
imglist[i].removeprefix(str(odir) + "/"),
|
||||||
|
imglist[i].removeprefix(str(odir) + "/.thumbnails/"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
file.write(self.endDiv())
|
||||||
|
file.write(self.endDiv())
|
||||||
|
file.write(self.footer)
|
||||||
|
|
||||||
|
def writeDetail(self, img, previmg, nextimg):
|
||||||
|
with open(f"build/{self.outfolder}/index.html", "w", encoding="utf-8") as file:
|
||||||
|
file.write(self.headermeta(title))
|
||||||
|
file.write(self.title(title))
|
||||||
|
file.write(self.img(image))
|
||||||
|
file.write(self.footer)
|
||||||
|
|
||||||
|
def writeMain(self):
|
||||||
|
with open(f"{str(BUILD_DIR)}/index.html", "w", encoding="utf-8") as file:
|
||||||
|
title="Chrissys random Imagelibrary"
|
||||||
|
file.write(self.headermeta(title))
|
||||||
|
file.write(self.title(title))
|
||||||
|
dirlist = [x[0] for x in os.walk(BUILD_DIR)]
|
||||||
|
for root, dirs, files in os.walk(BUILD_DIR):
|
||||||
|
|
||||||
|
for n in range(0,3):
|
||||||
|
file.write(self.div("column"))
|
||||||
|
for i in range(n, len(dirlist),3):
|
||||||
|
file.write(
|
||||||
|
self.aimg(
|
||||||
|
dirlist[i].removeprefix(str(BUILD_DIR) + "/"),
|
||||||
|
dirlist[i].removeprefix(str(BUILD_DIR) + "/"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
file.write(self.endDiv())
|
||||||
|
file.write(self.endDiv())
|
||||||
|
file.write(self.footer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EXIF:
|
class EXIF:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|
@ -51,40 +125,23 @@ class IMG:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
|
||||||
|
def createThumb(img, thumbdir):
|
||||||
|
file = Path(img).stem
|
||||||
|
with Image.open(img) as im:
|
||||||
|
im.thumbnail(THUMBSIZE)
|
||||||
|
im.convert("RGB").save(str(thumbdir) + "/" + file + ".jpg", "JPEG")
|
||||||
|
|
||||||
def createThumb(path, thumbdir):
|
|
||||||
size = 300,300
|
|
||||||
print(thumbdir)
|
|
||||||
for infile in glob.glob(str(path)+"/*.jpg" or str(path)+"/*.png"):
|
|
||||||
print(infile)
|
|
||||||
file = Path(infile).stem
|
|
||||||
ext = Path(infile).suffix
|
|
||||||
with Image.open(infile) as im:
|
|
||||||
im.thumbnail(size)
|
|
||||||
im.save(thumbdir/file, "JPEG")
|
|
||||||
|
|
||||||
def processImage():
|
def processImage(img, odir):
|
||||||
return
|
file = Path(img).stem
|
||||||
|
with Image.open(img) as im:
|
||||||
|
im.convert("RGB").save(str(odir) + "/" + file + ".jpg", "JPEG")
|
||||||
|
|
||||||
|
|
||||||
def generateDir(path):
|
def generateDir(path):
|
||||||
Path(BUILD_DIR/path.name).mkdir(parents=True, exist_ok=True)
|
Path(BUILD_DIR / path.name).mkdir(parents=True, exist_ok=True)
|
||||||
Path(BUILD_DIR/path.name/".thumbnails").mkdir(parents=True, exist_ok=True)
|
Path(BUILD_DIR / path.name / ".thumbnails").mkdir(parents=True, exist_ok=True)
|
||||||
return Path(BUILD_DIR/path.name), Path(BUILD_DIR/path.name/".thumbnails")
|
return Path(BUILD_DIR / path.name), Path(BUILD_DIR / path.name / ".thumbnails")
|
||||||
|
|
||||||
def writeHTML():
|
|
||||||
|
|
||||||
with open(f"build/{self.outfolder}/index.html", "w", encoding="utf-8") as file:
|
|
||||||
file.write(self.header)
|
|
||||||
file.write(self.setTitle(self.title))
|
|
||||||
file.write(self.div("row"))
|
|
||||||
for image in glob.glob("eh23" + "/*.jpg"):
|
|
||||||
file.write(self.div("column"))
|
|
||||||
file.write(self.postImage(image))
|
|
||||||
file.write(self.endDiv())
|
|
||||||
file.write(self.endDiv())
|
|
||||||
file.write(self.footer)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
@ -96,13 +153,13 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--inpath",
|
"--inpath",
|
||||||
type= lambda p: Path(p).absolute(),
|
type=lambda p: Path(p).absolute(),
|
||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--outpath",
|
"--outpath",
|
||||||
type= lambda p: Path(p).absolute(),
|
type=lambda p: Path(p).absolute(),
|
||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -115,13 +172,14 @@ if __name__ == "__main__":
|
||||||
print(args.inpath)
|
print(args.inpath)
|
||||||
|
|
||||||
odir, thumbdir = generateDir(args.inpath)
|
odir, thumbdir = generateDir(args.inpath)
|
||||||
createThumb(args.inpath, thumbdir)
|
|
||||||
|
for img in glob.glob(str(args.inpath) + "/*"):
|
||||||
|
print(img)
|
||||||
|
createThumb(img, thumbdir)
|
||||||
|
processImage(img, odir)
|
||||||
|
html = HTML()
|
||||||
|
html.writeIndex(thumbdir, odir, "eh23")
|
||||||
|
html.writeMain()
|
||||||
print(odir, thumbdir)
|
print(odir, thumbdir)
|
||||||
|
|
||||||
# for image in args.inpath:
|
# for image in args.inpath:
|
||||||
|
|
||||||
|
|
||||||
#index = HTML(outfolder="miau", title="miau")
|
|
||||||
#index.writeHTML()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue