diff --git a/gimmeme.py b/gimmeme.py deleted file mode 100644 index 65adfe5..0000000 --- a/gimmeme.py +++ /dev/null @@ -1,71 +0,0 @@ -import os -import asyncio -import aiohttp - -from dotenv import dotenv_values - -config = dotenv_values(".env") - -CHANNEL_IDS = [ - 367936426962190336, # TPM shitposts - 1095060717117374687, # aella memes -] - -headers = { - 'Authorization': config['DISCORD_AUTH'], -} - -async def save_img(session: aiohttp.ClientSession, url, guild_name, channel_name): - output_dir = f'./data/{guild_name}/{channel_name}' - filename = os.path.basename(url).split('?')[0] - - os.makedirs(output_dir, exist_ok=True); - - async with session.get(url) as response: - if response.status == 200: - print(filename) - with open(f'{output_dir}/{filename}', 'wb') as f: - f.write(await response.read()) - -async def fetch_channel_img_urls(session: aiohttp.ClientSession, channel_id): - url = f"https://discord.com/api/v9/channels/{channel_id}/messages" - async with session.get(url, headers=headers) as res: - json = await res.json() - url_lists = map(lambda msg: list( - map(lambda attachment: attachment['url'], msg['attachments']) - ), json) - return [item for group in url_lists for item in group] - -async def fetch_guild_details(session: aiohttp.ClientSession, guild_id): - url = f"https://discord.com/api/v9/guilds/{guild_id}" - async with session.get(url, headers=headers) as res: - return await res.json() - - -async def fetch_channel(session: aiohttp.ClientSession, channel_id): - url = f"https://discord.com/api/v9/channels/{channel_id}" - async with session.get(url, headers=headers) as res: - return await res.json() - - -async def download_channel_imgs(session, channel_id): - channel = await fetch_channel(session, channel_id) - guild = await fetch_guild_details(session, channel['guild_id']) - print(f"Fetching messages for channel guild={guild['name']} name={channel['name']} id={channel['id']}") - urls = await fetch_channel_img_urls(session, channel_id) - - tasks = [save_img( - session, - url, - channel_name=channel['name'], - guild_name=guild['name'], - ) for url in urls] - await asyncio.gather(*tasks) - - -async def main(): - async with aiohttp.ClientSession() as session: - channels = [download_channel_imgs(session, channel_id) for channel_id in CHANNEL_IDS] - await asyncio.gather(*channels) - -asyncio.run(main()) diff --git a/gimmeme.sublime-project b/gimmeme.sublime-project deleted file mode 100644 index d14f35b..0000000 --- a/gimmeme.sublime-project +++ /dev/null @@ -1,14 +0,0 @@ -{ - "folders": - [ - { - "path": "." - } - ], - "build_systems": [ - { - "name": "Python - gimmeme", - "cmd": ["$project_path/venv/bin/python3", "-u", "gimmeme.py"] - } - ] -} diff --git a/requirements.txt b/requirements.txt index 2cbc46e..f06d7c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ python-dotenv -requests -aiohttp \ No newline at end of file +aiohttp +google-cloud-vision \ No newline at end of file