I created an username checker against the anilist api. It basically checks usernames for availability to get 'rare' usernames. I'm trying to speed up the process by using threading but instead of checking different usernames it checks one username fifty times. How can I make it so that it checks different usernames per request in the threadpool.
My code:
def req_split(r):
global checked
global available
username = [line.strip() for line in open(f"external/{usernameFile}")]
for name in username:
data = {
"query": "mutation($name:String){CreateUser(userName:$name){id name about avatar{large}bannerImage unreadNotificationCount donatorTier donatorBadge moderatorRoles options{titleLanguage airingNotifications displayAdultContent profileColor notificationOptions{type enabled}}mediaListOptions{scoreFormat rowOrder animeList{customLists sectionOrder splitCompletedSectionByFormat advancedScoring advancedScoringEnabled}mangaList{customLists sectionOrder splitCompletedSectionByFormat advancedScoring advancedScoringEnabled}}}}",
"variables": {"name":name}}
headers = {
"Host": "anilist.co",
"schema": "internal",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
"Content-Type": "application/json"}
url = 'https://anilist.co/graphql'
req = requests.post(url+str(r), headers=headers, json=data)
if "userName" in req.text:
checked += 1
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Taken: {name}")
else:
checked += 1
available += 1
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Available: {name}")
with open('external/available.txt', "a") as av:
av.write(f'{username}\n')
data = range(0,5000)
with Pool(50) as p:
pm = p.imap_unordered(req_split,data)
pm = [i for i in pm if i]