Created
April 25, 2022 09:15
-
-
Save TobeTek/33a74a936a3554de9870aeb9e576fd8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./main.py | |
# ----------------------------------- | |
# new imports | |
import aiohttp | |
import asyncio | |
import async_api | |
import sync_api | |
from timeit import default_timer as timer | |
BASE_URL = "https://avatars.dicebear.com/api/{avatar_style}/{seed}" | |
ALL_STYLES = [ | |
"adventurer", | |
"adventurer-neutral", | |
"avataaars", | |
"big-ears", | |
"big-ears-neutral", | |
"big-smile", | |
"botts", | |
"croodles", | |
"micah" | |
] | |
def generate_profile_pics(n): | |
for _ in range(n): | |
sync_api.create_new_avatar(avatar_style="adventurer", base_url=BASE_URL) | |
async def async_generate_profile_pics(n): | |
Client = aiohttp.ClientSession() | |
Tasks = [] | |
for _ in range(n): | |
# Create a new profile pic | |
Tasks.append(async_api.aio_create_new_avatar(client_session=Client, avatar_style="big-smile", | |
base_url=BASE_URL)) | |
try: | |
await asyncio.gather(*Tasks) | |
except: | |
pass | |
finally: | |
await Client.close() | |
start = timer() | |
generate_profile_pics(20) | |
print(f"Time Elapsed: {timer()-start} seconds") | |
# For Windows Users | |
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) | |
start = timer() | |
asyncio.run(async_generate_profile_pics(20)) | |
print(f"Time Elapsed: {timer()-start} seconds") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment