Created
January 20, 2021 06:40
-
-
Save exherb/7cabc206c07b145939464a710d6deebb to your computer and use it in GitHub Desktop.
multiavatar
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
# -*- 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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个牛牪犇逼