feature: alt-text for photos
This commit is contained in:
@@ -144,6 +144,8 @@ class Build:
|
||||
file = f"{id}.jpg"
|
||||
try:
|
||||
shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file)
|
||||
if (self.config.p_data_photos / f"{id}.txt").exists():
|
||||
return (self.config.p_data_photos / f"{id}.txt").read_text()
|
||||
except FileNotFoundError:
|
||||
tqdm.write(f"\033[31mPhoto #{id} not found\033[0m")
|
||||
|
||||
|
||||
@@ -92,10 +92,19 @@ class Download:
|
||||
photos = self.api.get("items/Fotos", params={"limit": -1})
|
||||
|
||||
for photo in tqdm(photos, desc="Downloading photos"):
|
||||
# Save Photo to file
|
||||
data = self.api.get_file("assets/" + photo["photo"])
|
||||
with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file:
|
||||
file.write(data)
|
||||
|
||||
# Save Alt-Text to file
|
||||
prefix = ""
|
||||
if photo["alt_text"] is not None:
|
||||
if photo["alt_text_reviewed"] is None:
|
||||
prefix = "Der folgende Alt-Text wurde noch nicht geprüft: "
|
||||
with (self.config.p_data_photos / f"{photo['id']}.txt").open("w") as file:
|
||||
file.write(prefix + photo["alt_text"])
|
||||
|
||||
def download_pictures(self):
|
||||
self.config.p_data_pictures.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user