mirror of
https://github.com/Jylpah/blitz-tools.git
synced 2026-10-24 11:39:52 +02:00
getTitle(): read tank & map from replay metadata. DONE
This commit is contained in:
1 parent
66546ec57d
commit
ac74d45054
1 file changed
+16
-10
+16
-10
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3.8
|
#!/usr/bin/env python3.8
|
||||||
|
|
||||||
import json, argparse, inspect, sys, os, base64, aiohttp, urllib, asyncio, aiofiles, aioconsole
|
import json, argparse, inspect, sys, os, io, base64, aiohttp, urllib, asyncio, aiofiles, aioconsole
|
||||||
import logging, re, concurrent.futures, configparser, motor.motor_asyncio, ssl, zipfile
|
import logging, re, concurrent.futures, configparser, motor.motor_asyncio, ssl, zipfile
|
||||||
import blitzutils as bu
|
import blitzutils as bu
|
||||||
from blitzutils import WG
|
from blitzutils import WG
|
||||||
@@ -67,7 +67,7 @@ async def main(argv):
|
|||||||
parser = argparse.ArgumentParser(description='Post replays(s) to WoTinspector.com and retrieve replay data as JSON')
|
parser = argparse.ArgumentParser(description='Post replays(s) to WoTinspector.com and retrieve replay data as JSON')
|
||||||
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=WG_ACCOUNT, help='Uploader\'s WG account name. Format: ACCOUNT_NAME@SERVER')
|
parser.add_argument('-a', '--account', dest='account', type=str, default=WG_ACCOUNT, 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 automatic naming')
|
||||||
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('--tankopedia', type=str, default='tanks.json', help='JSON file to read Tankopedia from. Default: "tanks.json"')
|
parser.add_argument('--tankopedia', type=str, default='tanks.json', help='JSON file to read Tankopedia from. Default: "tanks.json"')
|
||||||
parser.add_argument('--mapfile', type=str, default='maps.json', help='JSON file to read Blitz map names from. Default: "maps.json"')
|
parser.add_argument('--mapfile', type=str, default='maps.json', help='JSON file to read Blitz map names from. Default: "maps.json"')
|
||||||
@@ -272,7 +272,6 @@ def getTitle_old(replayfile: str, title: str, i : int) -> str:
|
|||||||
|
|
||||||
def getTitle(replayfile: str, title: str, i : int) -> str:
|
def getTitle(replayfile: str, title: str, i : int) -> str:
|
||||||
global wg
|
global wg
|
||||||
|
|
||||||
if title == None:
|
if title == None:
|
||||||
try:
|
try:
|
||||||
filename = os.path.basename(replayfile)
|
filename = os.path.basename(replayfile)
|
||||||
@@ -281,13 +280,19 @@ def getTitle(replayfile: str, title: str, i : int) -> str:
|
|||||||
tank = None
|
tank = None
|
||||||
map_name = None
|
map_name = None
|
||||||
|
|
||||||
with zipfile.ZipFile(replayfile, 'r') as rp_archive:
|
with zipfile.ZipFile(replayfile, 'r') as archive:
|
||||||
with rp_archive.open('meta.json') as rp_metadata:
|
# bu.debug('Replay file: ' + replayfile + ' opened')
|
||||||
metadata_json = json.loads(rp_metadata)
|
with io.TextIOWrapper(archive.open('meta.json')) as meta:
|
||||||
player = metadata_json['playerName']
|
# bu.debug('Replay file\'s metadata: opened')
|
||||||
tank = wg.get_tank_name(metadata_json['playerVehicleName'])
|
try:
|
||||||
map_name = wg.get_map_name(metadata_json['mapName'])
|
metadata_json = json.load(meta)
|
||||||
if (player != None) and (tank != None) and (map_name != None):
|
#player = metadata_json['playerName']
|
||||||
|
tank = wg.get_tank_name(metadata_json['playerVehicleName'])
|
||||||
|
map_name = wg.get_map_name(metadata_json['mapName'])
|
||||||
|
bu.debug('Tank: ' + tank + ' Map: ' + map_name)
|
||||||
|
except Exception as err:
|
||||||
|
bu.error(exception = err)
|
||||||
|
if (tank != None) and (map_name != None):
|
||||||
title = tank + ' @ ' + map_name
|
title = tank + ' @ ' + map_name
|
||||||
else:
|
else:
|
||||||
title = re.sub('\\.wotbreplay$', '', filename)
|
title = re.sub('\\.wotbreplay$', '', filename)
|
||||||
@@ -295,6 +300,7 @@ def getTitle(replayfile: str, title: str, i : int) -> str:
|
|||||||
bu.error(err)
|
bu.error(err)
|
||||||
else:
|
else:
|
||||||
title.replace('NN', str(i))
|
title.replace('NN', str(i))
|
||||||
|
bu.debug('Returning: ' + title)
|
||||||
return title
|
return title
|
||||||
|
|
||||||
### main() -------------------------------------------
|
### main() -------------------------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user