aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-07-26 12:20:17 -0700
committerclarkzjw <[email protected]>2023-07-26 12:20:17 -0700
commitaababfa10094321c5f06b4cfdd28b6ef3a252846 (patch)
tree448d5df8a555649ff517f344a5a1dcc30e3437ed
parent78d996f287ecc2c4ab8c4580f8d2ba0a1eed963e (diff)
downloadphoto-aababfa10094321c5f06b4cfdd28b6ef3a252846.tar.gz
test exifexif
-rw-r--r--bot/Dockerfile3
-rw-r--r--bot/bot.py57
-rw-r--r--test.py22
3 files changed, 61 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
3WORKDIR /usr/src/app 3WORKDIR /usr/src/app
4 4
5COPY requirements.txt ./ 5COPY requirements.txt ./
6RUN pip install --no-cache-dir -r requirements.txt 6
7RUN apt-get update && apt-get install exiftool && pip install --no-cache-dir -r requirements.txt
7 8
8COPY . . 9COPY . .
9 10
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
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..ce1a747
--- /dev/null
+++ b/test.py
@@ -0,0 +1,22 @@
1from PIL import Image, ExifTags
2from PIL.ExifTags import TAGS
3from iptcinfo3 import IPTCInfo
4import exiftool
5import io
6
7im = Image.open("2023-03-10 17-49-50-00-IMG_8077.jpg")
8
9img_byte_arr = io.BytesIO()
10im.save(img_byte_arr, format='webp')
11img_byte_arr.seek(0)
12# img_byte_arr = img_byte_arr.getvalue()
13
14with exiftool.ExifToolHelper() as et:
15 metadata = et.get_metadata([img_byte_arr.getvalue()], raw_bytes=True)
16 for d in metadata:
17 # print("{:20.20} {:20.20}".format(d["SourceFile"],
18 # d["EXIF:DateTimeOriginal"]))
19 iso = d["EXIF:ISO"]
20 f = d["EXIF:FNumber"]
21 exp = d["EXIF:ExposureTime"]
22 print(f"{iso} {f} {exp}") \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)