Automatically migrated from Gitolite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.0 KiB

  1. #!/usr/bin/python
  2. import webshotslib, argparse
  3. parser = argparse.ArgumentParser(description='Finds usernames for Webshots')
  4. parser.add_argument('--resume', dest='resume', action='store', default='%',
  5. help='position to resume from')
  6. args = parser.parse_args()
  7. options = vars(args)
  8. users = []
  9. alphabet = "-0123456789abcdefghijklmnopqrstuvwxyz!"
  10. alphabet_length = len(alphabet)
  11. current_index = 0
  12. current_character_index = []
  13. current_character_index.insert(0, 0)
  14. done = False
  15. users_count = 0
  16. users_last_save = 0
  17. thousands_last_save = 0
  18. request_count = 0
  19. if options['resume'] != "%":
  20. # Resuming is requested, let's load the old user list first.
  21. user_list = open("users4.txt", "r")
  22. users = user_list.readlines()
  23. user_list.close()
  24. users_count = len(users)
  25. users_last_save = users_count
  26. thousands_last_save = users_count / 1000
  27. # Set the current state to the requested resume point
  28. if options['resume'].endswith("%"):
  29. options['resume'] = options['resume'][:-1]
  30. current_index = len(options['resume']) - 1
  31. current_character_index = []
  32. for character in options['resume']:
  33. current_character_index.append(alphabet.index(character))
  34. print "Resuming from %s%% - loaded %d users ..." % ("".join([alphabet[value] for value in current_character_index]), users_count)
  35. else:
  36. # Do an initial query for all the special character stuff
  37. results, count = webshotslib.search_query("%")
  38. # Append all users to the user list
  39. for user in results:
  40. if user not in users:
  41. users.append(user)
  42. users_count += 1
  43. while done == False:
  44. query = "".join([alphabet[value] for value in current_character_index])
  45. request_count += 1
  46. results, count = webshotslib.search_query(query)
  47. # Append all new users to the user list
  48. for user in results:
  49. if user not in users:
  50. users.append(user)
  51. users_count += 1
  52. # Save the users to a file if we've had another 1000 (approximately)
  53. if users_count % 1000 < 100 and users_last_save != users_count and thousands_last_save != users_count / 1000:
  54. print "\nSaving %d users to file..." % users_count
  55. userfile = open("users4.txt", "w")
  56. userfile.write("\n".join(users))
  57. userfile.close()
  58. users_last_save = users_count
  59. thousands_last_save = users_count / 1000
  60. elif request_count % 100 == 0:
  61. print "Users found so far: %s" % users_count
  62. # Decide what to do now
  63. if count < 100:
  64. # End of this query reached
  65. while True:
  66. if current_index >= 0:
  67. if current_character_index[current_index] < alphabet_length - 1:
  68. # More characters available, move on to the next character
  69. current_character_index[current_index] += 1
  70. print "\rMoving to next character, searching at %s%% ..." % "".join([alphabet[value] for value in current_character_index]),
  71. break
  72. else:
  73. # Ran out of characters, move up a level
  74. current_character_index.pop()
  75. current_index -= 1
  76. print "\nMoved up a level, searching at %s%% ..." % "".join([alphabet[value] for value in current_character_index])
  77. else:
  78. done = True
  79. print "\nDone!"
  80. exit(0)
  81. elif results[-1].lower().startswith(query):
  82. # Not specific enough, we need to go a level deeper
  83. current_index += 1
  84. current_character_index.insert(current_index, 0)
  85. print "\nIncreasing depth, searching at %s%% ..." % "".join([alphabet[value] for value in current_character_index])
  86. else:
  87. # Re-search with the current depth, with the start of the last result
  88. next_character = results[-1][current_index:current_index + 1].lower()
  89. try:
  90. current_character_index[current_index] = alphabet.index(next_character)
  91. except ValueError, e:
  92. # The next character is not in our list of characters, so we will append it to the alphabet.
  93. alphabet.append(next_character)
  94. alphabet_length = len(alphabet)
  95. print "\nAdded character %s to alphabet ..." % next_character
  96. print "\rContinuing search at %s%% ..." % "".join([alphabet[value] for value in current_character_index]),
  97. # Final save
  98. print "\nFinal save to file: %d users" % users_count
  99. userfile = open("users4.txt", "w")
  100. userfile.write("\n".join(users))
  101. userfile.close()