Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. import itertools
  2. import argparse
  3. import os
  4. import glob
  5. import sys
  6.  
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument("-uf", "--users-file", help="File with users and passwords", default="users.txt")
  9. parser.add_argument("-cf", "--coords-file", help="Coordinate files. Allows wildcards", default="*coords.txt")
  10. parser.add_argument("-st", "--steps", help="Steps per worker", default=5)
  11. parser.add_argument("-sd", "--scan-delay", help="Scan delay on each worker", default=4)
  12. parser.add_argument("-ld", "--login-delay", help="Delay between each login")
  13. parser.add_argument("-t", "--threads", help="Number of threads per worker", default=1, type=int)
  14. parser.add_argument("-od", "--output-dir", help="Directory where to store the Supervisord config files", default="/etc/supervisor/procs.d")
  15. parser.add_argument("-pd", "--pokemap-dir", help="Pokemon Go Map directory where the binary is located", default="/opt/pogo-map/" )
  16. parser.add_argument("-a", "--auth", help="Auth service", default="ptc")
  17.  
  18. coords = []
  19. users = []
  20.  
  21. class User(object):
  22. pass
  23.  
  24. # Parse the args
  25. args = parser.parse_args()
  26.  
  27. if not os.path.isdir( args.output_dir ):
  28. print "Invalid output directory. Does it exists?"
  29. sys.exit(1)
  30.  
  31. # Try to read the users file and store it on memory
  32. try:
  33. users_file = open(args.users_file)
  34. for line in users_file:
  35. username, password = line.rstrip().split(" ")
  36. user = User()
  37. user.username = username
  38. user.password = password
  39. users.append(user)
  40. except IOError as ioe:
  41. print "Error opening users file: " + ioe.filename + ": " + ioe.strerror
  42. sys.exit(1)
  43.  
  44. # Get all the coordinates files
  45. listing = glob.glob( args.coords_file )
  46.  
  47. for coord_filename in listing:
  48. try:
  49. coord_file = open( coord_filename )
  50. for line in coord_file:
  51. coords.append(line.rstrip())
  52. except IOError as ioe:
  53. print "Error opening users file: " + ioe.filename + ": " + ioe.strerror
  54. sys.exit(1)
  55.  
  56. print "Reading", len(users), "users and", len(coords), "locations and it's going to run", args.threads, "threads per location."
  57. print "This means you need", len(coords) * int(args.threads), "user accounts.\n"
  58.  
  59. if len(coords) * int(args.threads) > len(users):
  60. print "You need to have more accounts or less threads/locations. Please fix this."
  61. sys.exit(1)
  62.  
  63. print "Generating..."
  64.  
  65. # Removing old files
  66. os.system("rm -rf " + args.output_dir + "/*")
  67.  
  68. users.reverse() # Reverse the user list
  69. worker_id = 0
  70.  
  71. for location in coords:
  72. worker_id = worker_id + 1
  73. command = "/usr/bin/python runserver.py" + " -a " + args.auth + " -l \"" + location + "\""
  74. for x in range( 0, args.threads ):
  75. user = users.pop()
  76. command+=" -u " + user.username + " -p " + user.password
  77. if args.steps:
  78. command+=" -st " + str(args.steps)
  79. if args.scan_delay:
  80. command+=" -sd " + str(args.scan_delay)
  81. if args.login_delay:
  82. command+=" -ld " + str(args.login_delay)
  83.  
  84. command += " -ns"
  85.  
  86. config = ("[program:PokeGoMapWorker" + str(worker_id) + "]\n"
  87. "command=" + command + "\n"
  88. "numprocs=1\n"
  89. "directory=" + args.pokemap_dir + "\n"
  90. "startsec=15\n"
  91. "startretries=3\n"
  92. "autorestart=true\n"
  93. "stopwaitsecs=5\n"
  94. "stdout_logfile=/tmp/supervisor_worker" + str(worker_id) + ".log\n"
  95. "stderr_logfile=/tmp/supervisor_worker" + str(worker_id) + ".log\n"
  96. )
  97.  
  98. # Store the config
  99. file = open( args.output_dir + "/pogo_worker_"+ str(worker_id) + ".ini", "w" )
  100. file.write(config)
  101. file.close()
  102.  
  103. print "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement