From aababfa10094321c5f06b4cfdd28b6ef3a252846 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 26 Jul 2023 12:20:17 -0700 Subject: test exif --- bot/Dockerfile | 3 ++- bot/bot.py | 57 +++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 21 deletions(-) (limited to 'bot') diff --git a/bot/Dockerfile b/bot/Dockerfile index 6e97ed6..33c14fb 100644 --- a/bot/Dockerfile +++ b/bot/Dockerfile @@ -3,7 +3,8 @@ FROM python:3.10 WORKDIR /usr/src/app COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt + +RUN apt-get update && apt-get install exiftool && pip install --no-cache-dir -r requirements.txt COPY . . diff --git a/bot/bot.py b/bot/bot.py index 307f18f..859edae 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -13,6 +13,7 @@ from datetime import datetime import json import sys import httpx +import exiftool if os.getenv("DB_DRIVER") == "psql": @@ -145,18 +146,34 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await file.download_to_memory(img) try: - im = Image.open(img) - exif = im.getexif() - - camera_model = "" - shot_datetime = None - if exif: - for key, val in exif.items(): - if key in ExifTags.TAGS: - if ExifTags.TAGS[key] == "Model": - camera_model = val - elif ExifTags.TAGS[key] == "DateTime": - shot_datetime = datetime.strptime(val, "%Y:%m:%d %H:%M:%S") + # im = Image.open(img) + # exif = im.getexif() + # + # camera_model = "" + # shot_datetime = None + # if exif: + # for key, val in exif.items(): + # if key in ExifTags.TAGS: + # if ExifTags.TAGS[key] == "Model": + # camera_model = val + # elif ExifTags.TAGS[key] == "DateTime": + # shot_datetime = datetime.strptime(val, "%Y:%m:%d %H:%M:%S") + + with exiftool.ExifTool() as et: + metadata = et.get_metadata([bytes(img)]) + for d in metadata: + iso = d["EXIF:ISO"] + f = d["EXIF:FNumber"] + exp = d["EXIF:ExposureTime"] + print(f"{iso} {f} {exp}") + + # with exiftool.ExifToolHelper() as et: + # metadata = et.get_metadata([bytes(img)]) + # for d in metadata: + # iso = d["EXIF:ISO"] + # f = d["EXIF:FNumber"] + # exp = d["EXIF:ExposureTime"] + # print(f"{iso} {f} {exp}") output = io.BytesIO() im.save(output, format="webp", lossless=False, quality=80) @@ -179,14 +196,14 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: uploadedAt=datetime.now()) output.seek(0) - upload_to_s3(photo.fileId, output.read()) - - write_json() - response = httpx.post(cloudflare_pages_deploy_hook_url) - if response.status_code == 200: - await update.message.reply_markdown_v2(text="trigger deploy succeed") - else: - await update.message.reply_markdown_v2("trigger deploy failed, status: {}".format(response.status_code)) + # upload_to_s3(photo.fileId, output.read()) + + # write_json() + # response = httpx.post(cloudflare_pages_deploy_hook_url) + # if response.status_code == 200: + # await update.message.reply_markdown_v2(text="trigger deploy succeed") + # else: + # await update.message.reply_markdown_v2("trigger deploy failed, status: {}".format(response.status_code)) except Exception: await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) -- cgit v1.2.3