I'm trying to create a program that automatically creates accounts upon available usernames using api calls. The program works fine. However, I want it to run faster. Therefore I tried using threading but the problem is that whenever I use more than one thread my terminal creates a big mess. youtube video on what happens.
My code:
# Login --> Threading --> Checker
def login(self):
self.headers["Authorization"] = "Basic " + self.finalLogin
r = requests.post("https://public-ubiservices.ubi.com/v3/profiles/sessions", json={"Content-Type":"application/json"}, headers=self.headers)
if r.status_code == 200:
if r.json()["ticket"]:
token = "Ubi_v1 t=" + r.json()["ticket"]
self.headers['Authorization'] = token
self.threading()
def checker(self):
[self.usernames.put(line.strip()) for line in open("external/wordlist.txt")]
while not self.usernames.empty():
name = self.usernames.get(); self.usernames.put(name)
url = f"https://public-ubiservices.ubi.com/v3/profiles?nameOnPlatform={name}&platformType=uplay"
try:
r = requests.get(url, headers=self.headers)
if self.checkedCount % 100 == 0:
self.checkedCount += 1
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Message: Using new login")
self.accounts()
ctypes.windll.kernel32.SetConsoleTitleW(f"Gx | Checked: {self.checkedCount}, Available: {self.availableCount}, Errors: {self.errorCount}")
if r.status_code == 200:
self.checkedCount += 1
if len(r.json()['profiles']) != 0:
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Taken: {name}")
else:
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Available: {name}")
self.availableCount += 1
self.create(name)
else:
self.errorCount += 1
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Error: Check errors.txt")
with open('external/errors.txt', "a") as errorFile:
errorFile.write(f'{self.currentTime} | Error code: {r.status_code}, Error message: {r.text}\n')
self.checkedCount += 1
self.accounts()
except Exception:
self.errorCount += 1
pass
def threading(self):
[self.usernames.put(line.strip()) for line in open("external/wordlist.txt")]
for x in range(5):
threading.Thread(target=self.checker, args=()).start()