aktualisiert, ini parser
This commit is contained in:
parent
c4f990ea0c
commit
339cd88c6c
136
purrpic.py
136
purrpic.py
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
"""!@brief:generates static html imagelibrary
|
"""!@brief:generates static html imagelibrary
|
||||||
@author: Luzia Christiane Tesar
|
@author: Luzia Christiane Tesar
|
||||||
|
@date Mo 13. Jul 20:52:54 CEST 2026
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
@ -24,6 +25,8 @@ DESCRIPTION = ""
|
||||||
TODAY = datetime.datetime.today().strftime("%Y-%m-%d")
|
TODAY = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||||
CANONICALURL = "https://dm2lct.radio"
|
CANONICALURL = "https://dm2lct.radio"
|
||||||
|
|
||||||
|
exclude = set(['.thumbnails'])
|
||||||
|
|
||||||
class HTML:
|
class HTML:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.header = Path(CONF_DIR / "header.html").read_text()
|
self.header = Path(CONF_DIR / "header.html").read_text()
|
||||||
|
|
@ -37,6 +40,15 @@ class HTML:
|
||||||
def par(self, text):
|
def par(self, text):
|
||||||
return f"""<p>{text}</p>\n"""
|
return f"""<p>{text}</p>\n"""
|
||||||
|
|
||||||
|
def ul(self):
|
||||||
|
return f"""<ul>\n"""
|
||||||
|
|
||||||
|
def endUl(self):
|
||||||
|
return f"""</ul>\n"""
|
||||||
|
|
||||||
|
def li(self, text):
|
||||||
|
return f"""<li> {text}\n"""
|
||||||
|
|
||||||
def div(self, divclass):
|
def div(self, divclass):
|
||||||
return f"""<div class="{divclass}">\n"""
|
return f"""<div class="{divclass}">\n"""
|
||||||
|
|
||||||
|
|
@ -61,58 +73,70 @@ class HTML:
|
||||||
header = header.replace("{{language}}", LANGUAGE)
|
header = header.replace("{{language}}", LANGUAGE)
|
||||||
header = header.replace("{{description}}", DESCRIPTION)
|
header = header.replace("{{description}}", DESCRIPTION)
|
||||||
header = header.replace("{{published_date}}", TODAY)
|
header = header.replace("{{published_date}}", TODAY)
|
||||||
|
header = header.replace("{{modified_date}}", TODAY)
|
||||||
|
header = header.replace("{{canonical_URL}}", CANONICALURL)
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def writeIndex(self, indir, odir, title):
|
def writeIndex(self, indir, odir, title, info=None) -> None:
|
||||||
with open(f"{odir}/index.html", "w", encoding="utf-8") as file:
|
try:
|
||||||
breakpoint()
|
with open(f"{odir}/index.html", "w", encoding="utf-8") as file:
|
||||||
file.write(self.headermeta(title))
|
file.write(self.headermeta(title))
|
||||||
file.write(self.title(title))
|
file.write(self.title(title))
|
||||||
file.write(self.div("row"))
|
if info is not None:
|
||||||
imglist = glob.glob(str(odir) + "/.thumbnails/*")
|
file.write(self.ul())
|
||||||
for n in range(0,3):
|
for line in info:
|
||||||
file.write(self.div("column"))
|
file.write(self.li(line))
|
||||||
for i in range(n, len(imglist),3):
|
file.write(self.endUl())
|
||||||
file.write(
|
file.write(self.div("row"))
|
||||||
self.aimg(
|
imglist = glob.glob(str(odir) + "/.thumbnails/*")
|
||||||
imglist[i].removeprefix(str(odir) + "/"),
|
for n in range(0,3):
|
||||||
imglist[i].removeprefix(str(odir) + "/.thumbnails/"),
|
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.endDiv())
|
||||||
file.write(self.endDiv())
|
file.write(self.footer)
|
||||||
file.write(self.footer)
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def writeDetail(self, img, previmg, nextimg):
|
def writeDetail(self, img, previmg, nextimg):
|
||||||
|
buf+= self.headermeta(title)
|
||||||
|
buf+= self.title(title)
|
||||||
|
buf+= self.img(image)
|
||||||
|
buf+= self.footer
|
||||||
with open(f"build/{self.outfolder}/index.html", "w", encoding="utf-8") as file:
|
with open(f"build/{self.outfolder}/index.html", "w", encoding="utf-8") as file:
|
||||||
file.write(self.headermeta(title))
|
file.write(buf)
|
||||||
file.write(self.title(title))
|
|
||||||
file.write(self.img(image))
|
|
||||||
file.write(self.footer)
|
|
||||||
|
|
||||||
def writeMain(self):
|
def writeMain(self):
|
||||||
with open(f"{str(BUILD_DIR)}/index.html", "w", encoding="utf-8") as file:
|
with open(f"{str(BUILD_DIR)}/index.html", "w", encoding="utf-8") as file:
|
||||||
title="Chrissys random Imagelibrary"
|
title="Chrissys random Imagelibrary"
|
||||||
file.write(self.headermeta(title))
|
file.write(self.headermeta(title))
|
||||||
file.write(self.title(title))
|
file.write(self.title(title))
|
||||||
dirlist = [x[0] for x in os.walk(BUILD_DIR)]
|
file.write(self.div("row"))
|
||||||
for root, dirs, files in os.walk(BUILD_DIR):
|
dirs = list(filter(lambda x: x.is_dir(),os.scandir(BUILD_DIR)))
|
||||||
|
#dirs[:] = list(filter(lambda x: not x in exclude, dirs))
|
||||||
for n in range(0,3):
|
for n in range(0,3):
|
||||||
file.write(self.div("column"))
|
file.write(self.div("column"))
|
||||||
for i in range(n, len(dirlist),3):
|
for i in range(n, len(dirs),3):
|
||||||
|
thumbs = os.listdir(str(BUILD_DIR)+"/"+dirs[i].name+"/.thumbnails")
|
||||||
|
file.write(self.div("desc"))
|
||||||
|
file.write("EH23")
|
||||||
|
file.write(self.endDiv())
|
||||||
file.write(
|
file.write(
|
||||||
self.aimg(
|
self.aimg(
|
||||||
dirlist[i].removeprefix(str(BUILD_DIR) + "/"),
|
str(dirs[i].name)+"/.thumbnails/"+thumbs[0],
|
||||||
dirlist[i].removeprefix(str(BUILD_DIR) + "/"),
|
str(dirs[i].name)+"/"),
|
||||||
)
|
)
|
||||||
)
|
|
||||||
file.write(self.endDiv())
|
file.write(self.endDiv())
|
||||||
file.write(self.endDiv())
|
file.write(self.endDiv())
|
||||||
file.write(self.footer)
|
file.write(self.footer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EXIF:
|
class EXIF:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
|
|
@ -143,6 +167,37 @@ def generateDir(path):
|
||||||
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 parseIni(file):
|
||||||
|
title = ""
|
||||||
|
desc=[]
|
||||||
|
files = []
|
||||||
|
try:
|
||||||
|
with open(file, 'r') as f:
|
||||||
|
for line in f:
|
||||||
|
if line.startswith("desc = "):
|
||||||
|
desc.append(line.removeprefix("desc = ").strip())
|
||||||
|
elif line.endswith(".jpg\n" or ".png\n" or ".jpeg\n"):
|
||||||
|
files.append(line.strip())
|
||||||
|
elif line.startswith("title = "):
|
||||||
|
title=line.removeprefix("title = ").strip()
|
||||||
|
else:
|
||||||
|
next
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return files, desc, title
|
||||||
|
|
||||||
|
def processDir(path):
|
||||||
|
try:
|
||||||
|
if Path(path/".purrpic.ini").is_file():
|
||||||
|
files, desc, title = parseIni(Path(args.inpath/".purrpic.ini"))
|
||||||
|
odir, thumbdir = generateDir(args.inpath)
|
||||||
|
for img in files:
|
||||||
|
createThumb(Path(args.inpath/img), thumbdir)
|
||||||
|
processImage(Path(args.inpath/img), odir)
|
||||||
|
html = HTML()
|
||||||
|
html.writeIndex(thumbdir, odir, title, desc)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
|
@ -153,13 +208,13 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--inpath",
|
"--inpath",
|
||||||
type=lambda p: Path(p).absolute(),
|
type=lambda p: Path(p),
|
||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--outpath",
|
"--outpath",
|
||||||
type=lambda p: Path(p).absolute(),
|
type=lambda p: Path(p),
|
||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -169,17 +224,8 @@ if __name__ == "__main__":
|
||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(args.inpath)
|
|
||||||
|
|
||||||
odir, thumbdir = generateDir(args.inpath)
|
processDir(args.inpath)
|
||||||
|
|
||||||
for img in glob.glob(str(args.inpath) + "/*"):
|
html=HTML()
|
||||||
print(img)
|
|
||||||
createThumb(img, thumbdir)
|
|
||||||
processImage(img, odir)
|
|
||||||
html = HTML()
|
|
||||||
html.writeIndex(thumbdir, odir, "eh23")
|
|
||||||
html.writeMain()
|
html.writeMain()
|
||||||
print(odir, thumbdir)
|
|
||||||
|
|
||||||
# for image in args.inpath:
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue