diff options
author | clarkzjw <[email protected]> | 2023-07-26 12:20:17 -0700 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-07-26 12:20:17 -0700 |
commit | aababfa10094321c5f06b4cfdd28b6ef3a252846 (patch) | |
tree | 448d5df8a555649ff517f344a5a1dcc30e3437ed /bot | |
parent | 78d996f287ecc2c4ab8c4580f8d2ba0a1eed963e (diff) | |
download | photo-aababfa10094321c5f06b4cfdd28b6ef3a252846.tar.gz |
test exifexif
Diffstat (limited to 'bot')
-rw-r--r-- | bot/Dockerfile | 3 | ||||
-rw-r--r-- | bot/bot.py | 57 |
2 files changed, 39 insertions, 21 deletions
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 | |||
3 | WORKDIR /usr/src/app | 3 | WORKDIR /usr/src/app |
4 | 4 | ||
5 | COPY requirements.txt ./ | 5 | COPY requirements.txt ./ |
6 | RUN pip install --no-cache-dir -r requirements.txt | 6 | |
7 | RUN apt-get update && apt-get install exiftool && pip install --no-cache-dir -r requirements.txt | ||
7 | 8 | ||
8 | COPY . . | 9 | COPY . . |
9 | 10 | ||
@@ -13,6 +13,7 @@ from datetime import datetime | |||
13 | import json | 13 | import json |
14 | import sys | 14 | import sys |
15 | import httpx | 15 | import httpx |
16 | import exiftool | ||
16 | 17 | ||
17 | 18 | ||
18 | if os.getenv("DB_DRIVER") == "psql": | 19 | if os.getenv("DB_DRIVER") == "psql": |
@@ -145,18 +146,34 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |||
145 | await file.download_to_memory(img) | 146 | await file.download_to_memory(img) |
146 | 147 | ||
147 | try: | 148 | try: |
148 | im = Image.open(img) | 149 | # im = Image.open(img) |
149 | exif = im.getexif() | 150 | # exif = im.getexif() |
150 | 151 | # | |
151 | camera_model = "" | 152 | # camera_model = "" |
152 | shot_datetime = None | 153 | # shot_datetime = None |
153 | if exif: | 154 | # if exif: |
154 | for key, val in exif.items(): | 155 | # for key, val in exif.items(): |
155 | if key in ExifTags.TAGS: | 156 | # if key in ExifTags.TAGS: |
156 | if ExifTags.TAGS[key] == "Model": | 157 | # if ExifTags.TAGS[key] == "Model": |
157 | camera_model = val | 158 | # camera_model = val |
158 | elif ExifTags.TAGS[key] == "DateTime": | 159 | # elif ExifTags.TAGS[key] == "DateTime": |
159 | shot_datetime = datetime.strptime(val, "%Y:%m:%d %H:%M:%S") | 160 | # shot_datetime = datetime.strptime(val, "%Y:%m:%d %H:%M:%S") |
161 | |||
162 | with exiftool.ExifTool() as et: | ||
163 | metadata = et.get_metadata([bytes(img)]) | ||
164 | for d in metadata: | ||
165 | iso = d["EXIF:ISO"] | ||
166 | f = d["EXIF:FNumber"] | ||
167 | exp = d["EXIF:ExposureTime"] | ||
168 | print(f"{iso} {f} {exp}") | ||
169 | |||
170 | # with exiftool.ExifToolHelper() as et: | ||
171 | # metadata = et.get_metadata([bytes(img)]) | ||
172 | # for d in metadata: | ||
173 | # iso = d["EXIF:ISO"] | ||
174 | # f = d["EXIF:FNumber"] | ||
175 | # exp = d["EXIF:ExposureTime"] | ||
176 | # print(f"{iso} {f} {exp}") | ||
160 | 177 | ||
161 | output = io.BytesIO() | 178 | output = io.BytesIO() |
162 | im.save(output, format="webp", lossless=False, quality=80) | 179 | im.save(output, format="webp", lossless=False, quality=80) |
@@ -179,14 +196,14 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |||
179 | uploadedAt=datetime.now()) | 196 | uploadedAt=datetime.now()) |
180 | 197 | ||
181 | output.seek(0) | 198 | output.seek(0) |
182 | upload_to_s3(photo.fileId, output.read()) | 199 | # upload_to_s3(photo.fileId, output.read()) |
183 | 200 | ||
184 | write_json() | 201 | # write_json() |
185 | response = httpx.post(cloudflare_pages_deploy_hook_url) | 202 | # response = httpx.post(cloudflare_pages_deploy_hook_url) |
186 | if response.status_code == 200: | 203 | # if response.status_code == 200: |
187 | await update.message.reply_markdown_v2(text="trigger deploy succeed") | 204 | # await update.message.reply_markdown_v2(text="trigger deploy succeed") |
188 | else: | 205 | # else: |
189 | await update.message.reply_markdown_v2("trigger deploy failed, status: {}".format(response.status_code)) | 206 | # await update.message.reply_markdown_v2("trigger deploy failed, status: {}".format(response.status_code)) |
190 | except Exception: | 207 | except Exception: |
191 | await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) | 208 | await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) |
192 | 209 | ||