diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | _data/photos.json | 1 | ||||
-rw-r--r-- | bot.py | 14 |
3 files changed, 8 insertions, 9 deletions
@@ -1,3 +1,5 @@ | |||
1 | database/ | ||
2 | env | ||
1 | _drafts/ | 3 | _drafts/ |
2 | _site/ | 4 | _site/ |
3 | .DS_Store | 5 | .DS_Store |
diff --git a/_data/photos.json b/_data/photos.json index e69de29..9a46673 100644 --- a/_data/photos.json +++ b/_data/photos.json | |||
@@ -0,0 +1 @@ | |||
[{"guid": "61881B2D-1B87-4C7B-B4EB-063836F10C90", "fileId": "2023-02-28-23-39-47-IMG_0070.webp", "width": 5280, "height": 3512, "ratio": 1.5034168564920274, "orientation": "landscape", "path": "https://pixelstatic.jinwei.me/2023-02-28-23-39-47-IMG_0070.webp", "caption": "", "alt": "", "createdAt": "2023-02-28T23:39:47.000Z", "uploadedAt": "2023-02-28T23:39:47.000Z"}, {"guid": "B77DFD0A-342F-41F6-97ED-4FB289149A77", "fileId": "2023-02-28-23-43-55-IMG_0021.webp", "width": 5928, "height": 3992, "ratio": 1.4849699398797596, "orientation": "landscape", "path": "https://pixelstatic.jinwei.me/2023-02-28-23-43-55-IMG_0021.webp", "caption": "", "alt": "", "createdAt": "2023-02-28T23:43:55.000Z", "uploadedAt": "2023-02-28T23:43:55.000Z"}] \ No newline at end of file | |||
@@ -132,7 +132,7 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |||
132 | try: | 132 | try: |
133 | im = Image.open(img) | 133 | im = Image.open(img) |
134 | output = io.BytesIO() | 134 | output = io.BytesIO() |
135 | im.save(output, format="webp", lossless=True, quality=100) | 135 | im.save(output, format="webp", lossless=False, quality=80) |
136 | 136 | ||
137 | now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") | 137 | now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") |
138 | key_name = "{}-{}.webp".format(now, filename) | 138 | key_name = "{}-{}.webp".format(now, filename) |
@@ -145,8 +145,8 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |||
145 | ratio=im.width / im.height, | 145 | ratio=im.width / im.height, |
146 | orientation="landscape" if im.width > im.height else "portrait", | 146 | orientation="landscape" if im.width > im.height else "portrait", |
147 | path="https://pixelstatic.jinwei.me/{}".format(key_name), | 147 | path="https://pixelstatic.jinwei.me/{}".format(key_name), |
148 | caption="dsadas", | 148 | caption="", |
149 | alt="dsada", | 149 | alt="", |
150 | createdAt=datetime.now(), | 150 | createdAt=datetime.now(), |
151 | uploadedAt=datetime.now()) | 151 | uploadedAt=datetime.now()) |
152 | 152 | ||
@@ -154,13 +154,9 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |||
154 | upload_to_s3(photo.fileId, output.read()) | 154 | upload_to_s3(photo.fileId, output.read()) |
155 | 155 | ||
156 | write_json() | 156 | write_json() |
157 | await update.message.reply_markdown_v2(text="Sending processed result") | 157 | await update.message.reply_markdown_v2(text="Done") |
158 | 158 | ||
159 | await context.bot.send_document(chat_id=update.message.chat_id, | 159 | except Exception: |
160 | filename="{}-result.{}".format(filename, file_ext), | ||
161 | document=output.getvalue()) | ||
162 | |||
163 | except Exception as e: | ||
164 | await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) | 160 | await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) |
165 | 161 | ||
166 | 162 | ||