mirror of
https://github.com/Jylpah/blitz-tools.git
synced 2026-10-23 19:19:53 +02:00
Update wotbreplay_uploader.py
Added support for account nickname --account account_name@server where 'server' = ru | eu | na | asia
This commit is contained in:
1 parent
9287954e77
commit
b6b6377452
1 file changed
+45
-36
+45
-36
@@ -1,12 +1,13 @@
|
|||||||
#!/usr/bin/python3.7
|
#!/usr/bin/python3.7
|
||||||
|
|
||||||
import json, argparse, inspect, sys, os, base64, aiohttp, urllib, asyncio, aiofiles, aioconsole, logging, re
|
import json, argparse, inspect, sys, os, base64, aiohttp, urllib, asyncio, aiofiles, aioconsole, logging, re
|
||||||
|
from WG_utils import WG
|
||||||
|
|
||||||
logging.getLogger("asyncio").setLevel(logging.DEBUG)
|
logging.getLogger("asyncio").setLevel(logging.DEBUG)
|
||||||
|
|
||||||
# WG account id of the uploader:
|
# WG account id of the uploader:
|
||||||
# # Find it here: https://developers.wargaming.net/reference/all/wotb/account/list/
|
# # Find it here: https://developers.wargaming.net/reference/all/wotb/account/list/
|
||||||
WG_ID = USE_YOUR_OWN_WG_ID
|
WG_ID = None
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
VERBOSE = False
|
VERBOSE = False
|
||||||
@@ -14,37 +15,40 @@ SLEEP = 2
|
|||||||
MAX_RETRIES = 3
|
MAX_RETRIES = 3
|
||||||
REPLAY_N = 0
|
REPLAY_N = 0
|
||||||
WIurl='https://wotinspector.com/api/replay/upload?'
|
WIurl='https://wotinspector.com/api/replay/upload?'
|
||||||
|
WG_appID = '81381d3f45fa4aa75b78a7198eb216ad'
|
||||||
|
wg = None
|
||||||
|
|
||||||
TANKS = None
|
# TANKS = None
|
||||||
MAPS ={
|
# MAPS ={
|
||||||
'amigosville' : 'Falls Creek',
|
# 'amigosville' : 'Falls Creek',
|
||||||
'canal' : 'Canal',
|
# 'canal' : 'Canal',
|
||||||
'canyon' : 'Canyon',
|
# 'canyon' : 'Canyon',
|
||||||
'desert_train' : 'Desert Sands',
|
# 'desert_train' : 'Desert Sands',
|
||||||
'erlenberg' : 'Middleburg',
|
# 'erlenberg' : 'Middleburg',
|
||||||
'fort' : 'Fort Despair',
|
# 'fort' : 'Fort Despair',
|
||||||
'grossberg' : 'Dynasty\'s Pearl',
|
# 'grossberg' : 'Dynasty\'s Pearl',
|
||||||
'faust' : 'Faust',
|
# 'faust' : 'Faust',
|
||||||
'himmelsdorf' : 'Himmelsdorf',
|
# 'himmelsdorf' : 'Himmelsdorf',
|
||||||
'italy' : 'Vineyeards',
|
# 'italy' : 'Vineyeards',
|
||||||
'karelia' : 'Rockfield',
|
# 'karelia' : 'Rockfield',
|
||||||
'milbase' : 'Yamato Harbor',
|
# 'milbase' : 'Yamato Harbor',
|
||||||
'mountain' : 'Black Goldville',
|
# 'mountain' : 'Black Goldville',
|
||||||
'port' : 'Port Bay',
|
# 'port' : 'Port Bay',
|
||||||
'medvedkovo' : 'Dead Rail',
|
# 'medvedkovo' : 'Dead Rail',
|
||||||
'pliego' : 'Castilla',
|
# 'pliego' : 'Castilla',
|
||||||
'rock' : 'Mayan Ruins',
|
# 'rock' : 'Mayan Ruins',
|
||||||
'rudniki' : 'Mines',
|
# 'rudniki' : 'Mines',
|
||||||
'savanna' : 'Oasis Palms',
|
# 'savanna' : 'Oasis Palms',
|
||||||
'skit' : 'Naval Frontier'
|
# 'skit' : 'Naval Frontier'
|
||||||
}
|
# }
|
||||||
|
|
||||||
async def main(argv):
|
async def main(argv):
|
||||||
global VERBOSE, DEBUG, TANKS
|
global VERBOSE, DEBUG, wg
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Post replays(s) to WoTinspector.com and retrieve battle data')
|
parser = argparse.ArgumentParser(description='Post replays(s) to WoTinspector.com and retrieve battle data')
|
||||||
parser.add_argument('--output', default='single', choices=['file', 'files', 'db'] , help='Select output mode: single/multiple files or database')
|
parser.add_argument('--output', default='single', choices=['file', 'files', 'db'] , help='Select output mode: single/multiple files or database')
|
||||||
parser.add_argument('-id', dest='accountID', type=int, default=WG_ID, help='WG account_id')
|
parser.add_argument('-id', dest='accountID', type=int, default=WG_ID, help='WG account_id')
|
||||||
|
parser.add_argument('-a', '--account', dest='account', type=str, default=None, help='Uploader\'s WG account name. Format: ACCOUNT_NAME@SERVER')
|
||||||
parser.add_argument('-t','--title', type=str, default=None, help='Title for replays. Use NN for continous numbering. Default is filename-based numbering')
|
parser.add_argument('-t','--title', type=str, default=None, help='Title for replays. Use NN for continous numbering. Default is filename-based numbering')
|
||||||
parser.add_argument('-p', '--private', dest="private", action='store_true', default=False, help='Set replays private on WoTinspector.com')
|
parser.add_argument('-p', '--private', dest="private", action='store_true', default=False, help='Set replays private on WoTinspector.com')
|
||||||
parser.add_argument('--tasks', dest='N_tasks', type=int, default=10, help='Number of worker threads')
|
parser.add_argument('--tasks', dest='N_tasks', type=int, default=10, help='Number of worker threads')
|
||||||
@@ -54,14 +58,15 @@ async def main(argv):
|
|||||||
parser.add_argument('files', metavar='FILE1 [FILE2 ...]', type=str, nargs='+', help='Files to read. Use \'-\' for STDIN"')
|
parser.add_argument('files', metavar='FILE1 [FILE2 ...]', type=str, nargs='+', help='Files to read. Use \'-\' for STDIN"')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print(args)
|
|
||||||
VERBOSE = args.verbose
|
VERBOSE = args.verbose
|
||||||
DEBUG = args.debug
|
DEBUG = args.debug
|
||||||
if DEBUG: VERBOSE = True
|
if DEBUG: VERBOSE = True
|
||||||
|
|
||||||
|
wg = WG(WG_appID, args.tankopedia)
|
||||||
|
|
||||||
if args.tankopedia != None:
|
if args.account != None:
|
||||||
with open(args.tankopedia, 'r', encoding='utf8') as f:
|
args.accountID = await wg.getAccountID(args.account)
|
||||||
TANKS = json.load(f)
|
debug('WG account_id: ' + str(args.accountID))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
queue = asyncio.Queue()
|
queue = asyncio.Queue()
|
||||||
@@ -84,10 +89,13 @@ async def main(argv):
|
|||||||
debug('Waiting for workers to cancel')
|
debug('Waiting for workers to cancel')
|
||||||
await asyncio.gather(*tasks, return_exceptions=True)
|
await asyncio.gather(*tasks, return_exceptions=True)
|
||||||
verbose(str(REPLAY_N) + ' replays uploaded')
|
verbose(str(REPLAY_N) + ' replays uploaded')
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('Ctrl-c pressed ...')
|
print('Ctrl-c pressed ...')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
finally:
|
||||||
|
## Need to close the aiohttp.session since Python destructors do not support async methods...
|
||||||
|
await wg.session.close()
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -196,22 +204,24 @@ async def storeReplayJSON(filename: str, json_data : dict):
|
|||||||
|
|
||||||
|
|
||||||
def getTitle(replayfile: str, title: str, i : int) -> str:
|
def getTitle(replayfile: str, title: str, i : int) -> str:
|
||||||
|
global wg
|
||||||
|
|
||||||
if title == None:
|
if title == None:
|
||||||
try:
|
try:
|
||||||
filename = os.path.basename(replayfile)
|
filename = os.path.basename(replayfile)
|
||||||
# debug(filename)
|
# debug(filename)
|
||||||
p = re.compile('\\d{8}_\\d{4}_(.+)_(' + '|'.join(MAPS.keys()) + ')(?:-\\d)?\\.wotbreplay$')
|
map_usrStrs = wg.getMapUserStrs()
|
||||||
|
p = re.compile('\\d{8}_\\d{4}_(.+)_(' + '|'.join(map_usrStrs) + ')(?:-\\d)?\\.wotbreplay$')
|
||||||
m = p.match(filename)
|
m = p.match(filename)
|
||||||
if (m != None):
|
if (m != None):
|
||||||
# debug('Match')
|
# debug('Match')
|
||||||
if TANKS != None:
|
if wg.tanks != None:
|
||||||
tank = TANKS['userStr'][m.group(1)]
|
tank = wg.tanks['userStr'][m.group(1)]
|
||||||
# debug('Tank from Tankopedia:' + tank)
|
# debug('Tank from Tankopedia:' + tank)
|
||||||
else:
|
else:
|
||||||
tank = m.group(1)
|
tank = m.group(1)
|
||||||
# debug(tank)
|
# debug(tank)
|
||||||
blitz_map = MAPS[m.group(2)]
|
blitz_map = wg.maps[m.group(2)]
|
||||||
title = tank + ' @ ' + blitz_map
|
title = tank + ' @ ' + blitz_map
|
||||||
else:
|
else:
|
||||||
# debug('No match')
|
# debug('No match')
|
||||||
@@ -252,5 +262,4 @@ def error(msg = ""):
|
|||||||
|
|
||||||
### main()
|
### main()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# use debug=True to better debug the code
|
|
||||||
asyncio.run(main(sys.argv[1:]), debug=False)
|
asyncio.run(main(sys.argv[1:]), debug=False)
|
||||||
Reference in new issue
Block a user