Advertisement
paster442

3-letter Scratch usernames finder (Python)

Aug 2nd, 2021 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. import time, os, requests, math, concurrent.futures as cf, sys
  2.  
  3. start_time = time.time()
  4.  
  5. f = open(os.path.join("/storage/emulated/0/Download", "usernames.txt"), "a")
  6. #f = open("usernames.txt", "a")
  7.  
  8. CONNECTIONS = 20
  9.  
  10. def get_usernames():
  11.     my_list = list()
  12.  
  13.     alphabet = "abcdefghijklmnopqrstuvwxyz1234567890-_"
  14.  
  15.     a = alphabet[0:26] # letters
  16.     b = alphabet[36:38] # dash and underscore
  17.     c = alphabet[26:36] # numbers
  18.    
  19.     for l1 in alphabet[14:38]: # opqrstuvwxyz1234567890-_
  20.         for l2 in alphabet:
  21.             for l3 in alphabet:
  22.                 user = l1 + l2 + l3
  23.                
  24.                 cond1 = l1 in a and l2 in a and l3 in a
  25.                 cond2 = l1 in b and l2 in b and l3 in b
  26.                 cond3 = l1 in c and l2 in c and l3 in c
  27.  
  28.                 if not cond1 and not cond2 and not cond3:
  29.                     my_list.append(user)
  30.     return my_list
  31.  
  32. def check_username(username):
  33.     r = requests.get(f'https://api.scratch.mit.edu/accounts/checkusername/{username}/')
  34.     return r.text != '{"username":"' + username + '","msg":"valid username"}'
  35.  
  36. def write_to_file(list):
  37.     for item in list:
  38.         f.write(item.upper() + "\n")
  39.  
  40. usernames = get_usernames()
  41.  
  42. available_usernames = list()
  43. combinations = int(math.ceil(len(usernames) / 10.0)) * 10 # it's 25536 but we round it up to 25540 because we can divide 25540 by 10
  44. counter = 0
  45.  
  46. with cf.ThreadPoolExecutor(max_workers = CONNECTIONS) as executor:
  47.     future_to_url = {executor.submit(check_username, username): username for username in usernames}
  48.     for future in cf.as_completed(future_to_url):
  49.  
  50.         counter += 1
  51.         if counter % (combinations / 10) == 0.0:
  52.             print(str(int((counter / combinations) * 100)) + " % Done")
  53.  
  54.         username = future_to_url[future]
  55.         if not future.result():
  56.             available_usernames.append(username)
  57.  
  58. print("100 % Done")
  59.  
  60. available_usernames = sorted(available_usernames, key = lambda src: ["abcdefghijklmnopqrstuvwxyz1234567890-_".index(char) for char in src])
  61.  
  62. f.truncate(0) # clear file contents
  63. write_to_file(available_usernames)
  64. f.close()
  65.  
  66. print("\n" + "Execution Time: " + str(round(((time.time() - start_time)/60), 3)) + " Minutes")
  67. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement