Skip to content

Instantly share code, notes, and snippets.

@exherb
Created January 20, 2021 06:40
Show Gist options
  • Save exherb/7cabc206c07b145939464a710d6deebb to your computer and use it in GitHub Desktop.
Save exherb/7cabc206c07b145939464a710d6deebb to your computer and use it in GitHub Desktop.
multiavatar
# -*- coding: utf-8 -*-
import itertools
import os
import sys
import time
import requests
def download(word: str, to: str) -> None:
word = word.lower()
words = []
for i in range(len(word) + 1):
for indexes in itertools.combinations(range(len(word)), i):
chars = list(word)
for i in indexes:
chars[i] = chars[i].upper()
words.append("".join(chars))
for i, word in enumerate(words):
url = f"https://api.multiavatar.com/{word}.png"
path = f"{to}/{word}-{i}.png"
if os.path.exists(path):
continue
with open(path, "wb") as f:
while True:
content = requests.get(url).content
if content.find(b"Limit reached") >= 0:
time.sleep(30)
else:
break
f.write(content)
if __name__ == "__main__":
download(sys.argv[1], sys.argv[2])
@bloodynumen
Copy link

cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment