paster442

All available 3-letter usernames for Scratch, my code

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