Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #6140

Merged
merged 3 commits into from
Jul 26, 2017
Merged

Dev #6140

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions MultiBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# the above tag defines encoding for this document and is for Python 2.x compatibility
import gzip
import json
import multiprocessing
import os
import platform
import re
Expand All @@ -17,12 +18,15 @@
hashkeyCur = 0
accountNum = 0
try:
os.stat('configs/temp')
os.rmdir('configs/temp')
except:
os.mkdir('configs/temp')
pass
try:
os.mkdir('configs/temp')
except:
pass
AccountLock = Semaphore(value=1)
MultiBotConfig = json.loads(open('configs/MultiBotConfig.json').read())
ThreadNum = MultiBotConfig[u'Threads']

def getProxy():
try:
Expand Down Expand Up @@ -89,11 +93,9 @@ def AccountManager(Account=None):
Accounts.append(Account)
AccountLock.release()

def MakeConf(CurThread):
def MakeConf(CurThread, username, password):
try:
jsonData = json.loads(open('configs/' + MultiBotConfig[u'AuthJsonFile']).read())
Account = AccountManager()
username, password = Account.split(':')
jsonData[u'username'] = username
jsonData[u'password'] = password
jsonData[u'hashkey'] = getHashKey()
Expand All @@ -111,42 +113,45 @@ def MakeConf(CurThread):
except:
pass
try:
jsonData[u'websocket'][u'server_url'] = MultiBotConfig[u'WebSocket'][u'IP'] + ':' + str(MultiBotConfig[u'WebSocket'][u'Port'] + CurThread)
if jsonData[u'websocket'][u'start_embedded_server']:
jsonData[u'websocket'][u'server_url'] = MultiBotConfig[u'WebSocket'][u'IP'] + ':' + str(MultiBotConfig[u'WebSocket'][u'Port'] + CurThread)
except:
pass
print 'error websocket'

with open('configs/temp/config-' + str(CurThread) + '.json', 'w') as s:
s.write(json.dumps(jsonData))
s.close()

except IOError:
print 'config file error'
time.sleep(30)

class ThreadClass(threading.Thread):
def run(self):
CurThread = int(self.getName().replace('Thread-', '')) -1
self.CurThread = int(self.getName().replace('Thread-', '')) -1
while True:
Account = AccountManager()
username, password = Account.split(':')
self.Account = AccountManager()
self.username, self.password = self.Account.split(':')
print 'Thread-{0} using account {1}'.format(self.CurThread, self.username)
try:
MakeConf(CurThread)
MakeConf(self.CurThread, self.username, self.password)
if MultiBotConfig[u'UseProxy']:
proxy = getProxy()
self.proxy = getProxy()
if platform.system() == "Linux":
os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"')
self.os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"')
if platform.system() == "Windows":
os.system('')
self.os.system('')
os.system(
"python pokecli.py -af configs/temp/auth-{0}.json -cf configs/temp/config-{0}.json --walker_limit_output {1}".format(
CurThread, MultiBotConfig[u'walker_limit_output']))
self.CurThread, MultiBotConfig[u'walker_limit_output']))
except Exception as e:
import traceback
print("Generic Exception: " + traceback.format_exc())
finally:
AccountManager(Account)
AccountManager(self.Account)
time.sleep (60)
def start():
for i in range(ThreadNum):
for i in range(MultiBotConfig[u'Threads']):
t = ThreadClass()
time.sleep (0.1)
t.start()
Expand Down
3 changes: 2 additions & 1 deletion configs/MultiBotConfig.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"ConfigJsonFile": "config.json",
"CompleteTutorialNickName": true,
"WebSocket": {
"start_embedded_server": false,
"IP": "127.0.0.1",
"Port": "4000"
"Port": 4000
},
"walker_limit_output": true
}