Skip to content

Instantly share code, notes, and snippets.

@vaurdan
Created August 2, 2016 15:25
Show Gist options
  • Save vaurdan/d078a43de5daa8917851a441066e4e2e to your computer and use it in GitHub Desktop.
Save vaurdan/d078a43de5daa8917851a441066e4e2e to your computer and use it in GitHub Desktop.
Generates supervisord config files
import itertools
import argparse
import os
import glob
import sys
parser = argparse.ArgumentParser()
parser.add_argument("-uf", "--users-file", help="File with users and passwords", default="users.txt")
parser.add_argument("-cf", "--coords-file", help="Coordinate files. Allows wildcards", default="*coords.txt")
parser.add_argument("-st", "--steps", help="Steps per worker", default=5)
parser.add_argument("-sd", "--scan-delay", help="Scan delay on each worker", default=4)
parser.add_argument("-ld", "--login-delay", help="Delay between each login")
parser.add_argument("-t", "--threads", help="Number of threads per worker", default=1, type=int)
parser.add_argument("-od", "--output-dir", help="Directory where to store the Supervisord config files", default="/etc/supervisor/procs.d")
parser.add_argument("-pd", "--pokemap-dir", help="Pokemon Go Map directory where the binary is located", default="/opt/pogo-map/" )
parser.add_argument("-a", "--auth", help="Auth service", default="ptc")
coords = []
users = []
class User(object):
pass
# Parse the args
args = parser.parse_args()
if not os.path.isdir( args.output_dir ):
print "Invalid output directory. Does it exists?"
sys.exit(1)
# Try to read the users file and store it on memory
try:
users_file = open(args.users_file)
for line in users_file:
username, password = line.rstrip().split(" ")
user = User()
user.username = username
user.password = password
users.append(user)
except IOError as ioe:
print "Error opening users file: " + ioe.filename + ": " + ioe.strerror
sys.exit(1)
# Get all the coordinates files
listing = glob.glob( args.coords_file )
for coord_filename in listing:
try:
coord_file = open( coord_filename )
for line in coord_file:
coords.append(line.rstrip())
except IOError as ioe:
print "Error opening users file: " + ioe.filename + ": " + ioe.strerror
sys.exit(1)
print "Reading", len(users), "users and", len(coords), "locations and it's going to run", args.threads, "threads per location."
print "This means you need", len(coords) * int(args.threads), "user accounts.\n"
if len(coords) * int(args.threads) > len(users):
print "You need to have more accounts or less threads/locations. Please fix this."
sys.exit(1)
print "Generating..."
# Removing old files
os.system("rm -rf " + args.output_dir + "/*")
users.reverse() # Reverse the user list
worker_id = 0
for location in coords:
worker_id = worker_id + 1
command = "/usr/bin/python runserver.py" + " -a " + args.auth + " -l \"" + location + "\""
for x in range( 0, args.threads ):
user = users.pop()
command+=" -u " + user.username + " -p " + user.password
if args.steps:
command+=" -st " + str(args.steps)
if args.scan_delay:
command+=" -sd " + str(args.scan_delay)
if args.login_delay:
command+=" -ld " + str(args.login_delay)
command += " -ns"
config = ("[program:PokeGoMapWorker" + str(worker_id) + "]\n"
"command=" + command + "\n"
"numprocs=1\n"
"directory=" + args.pokemap_dir + "\n"
"startsec=15\n"
"startretries=3\n"
"autorestart=true\n"
"stopwaitsecs=5\n"
"stdout_logfile=/tmp/supervisor_worker" + str(worker_id) + ".log\n"
"stderr_logfile=/tmp/supervisor_worker" + str(worker_id) + ".log\n"
)
# Store the config
file = open( args.output_dir + "/pogo_worker_"+ str(worker_id) + ".ini", "w" )
file.write(config)
file.close()
print "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment