aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'bot/bot.py')
-rw-r--r--bot/bot.py57
1 files changed, 37 insertions, 20 deletions
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
13import json 13import json
14import sys 14import sys
15import httpx 15import httpx
16import exiftool
16 17
17 18
18if os.getenv("DB_DRIVER") == "psql": 19if 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
Powered by cgit v1.2.3 (git 2.41.0)