From e6d773f70aef721e739229b91e82140b4e4029ff Mon Sep 17 00:00:00 2001 From: dsc Date: Mon, 5 Sep 2022 15:38:03 +0300 Subject: [PATCH] Switch image host to lewd --- main.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index f31c697..1679e02 100644 --- a/main.py +++ b/main.py @@ -85,7 +85,33 @@ class Task: bg.paste(img, (x_start + x_offset, y_start + y_offset)) return bg - async def post_image(self, image: BytesIO) -> str: + async def post_image_lewd(self, image) -> str: + timeout = aiohttp.ClientTimeout(total=5) + + data = aiohttp.FormData() + data.add_field('fileToUpload', image, filename='lol.jpg', content_type='image/jpg') + data.add_field('exifData', 'Yes') + data.add_field('submiter', 'Upload') + data.add_field('iUrl', '') + data.add_field('iUrlb', '') + + try: + async with aiohttp.ClientSession( + timeout=timeout, + headers={"User-Agent": "w0w"}) as session: + async with session.post('https://lewd.pics/p/', data=data) as resp: + body = await resp.read() + + re_rule = R"lewd\.pics\/p\/([a-zA-Z.]+)\"" + blobs = re.findall(re_rule, body.decode()) + uid = blobs[0] + + return f"https://lewd.pics/p/{uid}" + + except Exception as ex: + raise Exception("Could not upload file to lewd.pics :((") + + async def post_image_uguu(self, image: BytesIO) -> str: url = 'https://uguu.se/upload.php' timeout = aiohttp.ClientTimeout(total=5) @@ -247,9 +273,9 @@ async def main(): image_bytes.seek(0) try: - url = await task.post_image(image_bytes) + url = await task.post_image_lewd(image_bytes) except Exception as ex: - _err(task, err=f"uguu upload: {ex}") + _err(task, err=f"image upload: {ex}") _lower_author_task_count(task.author) continue