Browse Source

alttext done by redistribusi

main
crunk 5 months ago
parent
commit
64feae3475
  1. 2
      requirements.txt
  2. 22
      verse/describer/describe_files.py
  3. 2
      verse/distribusikan/distribusi_workflow.py

2
requirements.txt

@ -8,7 +8,7 @@ bleach-allowlist==1.0.3
blinker==1.7.0 blinker==1.7.0
cffi cffi
click==8.1.7 click==8.1.7
distribusi @ git+https://git.vvvvvvaria.org/crunk/distribusi@4cb03d1131a43669912433b0a5c18596712add20 distribusi @ git+https://git.vvvvvvaria.org/crunk/distribusi@5934122c6ec1452d975b7cfe6582f9417fd5fdd0
dnspython==2.1.0 dnspython==2.1.0
email-validator==1.1.3 email-validator==1.1.3
Flask==3.0.3 Flask==3.0.3

22
verse/describer/describe_files.py

@ -15,7 +15,8 @@ from sqlalchemy.exc import (
InterfaceError, InterfaceError,
InvalidRequestError, InvalidRequestError,
) )
from exif import Image import piexif
from PIL import Image
from app import db from app import db
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
from models.distribusi_file_model import DistribusiFiles from models.distribusi_file_model import DistribusiFiles
@ -76,7 +77,7 @@ def describe_file(file_id):
distribusi_file.id, distribusi_file.path, distribusi_file.type distribusi_file.id, distribusi_file.path, distribusi_file.type
) )
save_described_file_to_db(describe_form, distribusi_file) save_described_file_to_db(describe_form, distribusi_file)
add_exif_to_image(describe_form, distribusi_file) add_alttext_to_file(describe_form, distribusi_file)
distribusi = Distribusis.query.filter_by( distribusi = Distribusis.query.filter_by(
id=distribusi_file.distribusi id=distribusi_file.distribusi
).first() ).first()
@ -138,19 +139,10 @@ def save_described_file_to_db(describe_form, distribusi_file):
flash("Error connecting to the database", "danger") flash("Error connecting to the database", "danger")
def add_exif_to_image(describe_form, distribusi_file): def add_alttext_to_file(describe_form, distribusi_file):
if not describe_form.alttext.data: if not describe_form.alttext.data:
return return
if distribusi_file.type != "image": filename_no_ext = os.path.splitext(distribusi_file.path)[0]
return with open(f'{filename_no_ext}_alttext.txt', 'w') as alttext_file:
updating_image = bytearray() alttext_file.write(describe_form.alttext.data)
with open(distribusi_file.path, "rb") as image_file:
image_bytes = image_file.read()
updating_image = Image(image_bytes)
updating_image.communication = describe_form.alttext.data
with open(distribusi_file.path, "wb") as new_image_file:
new_image_file.write(updating_image.get_file())
print(
f"{updating_image.communication} is set from form data: {describe_form.alttext.data}"
)
return return

2
verse/distribusikan/distribusi_workflow.py

@ -98,7 +98,7 @@ def get_css_file(distribusi):
def run_distribusi(userfolder, cssfile): def run_distribusi(userfolder, cssfile):
print(f"Run distribusi on this folder: {userfolder} with css:{cssfile}") print(f"Run distribusi on this folder: {userfolder} with css:{cssfile}")
parser = build_argparser() parser = build_argparser()
args = parser.parse_args(["-t", "--menu-with-index", "-s", cssfile]) args = parser.parse_args(["-t", "-a", "--menu-with-index", "-s", cssfile])
distribusify(args, userfolder) distribusify(args, userfolder)

Loading…
Cancel
Save