From deb907605db8985163b65161b8dc91b8c09f09d8 Mon Sep 17 00:00:00 2001 From: Jylpah Date: Sun, 4 Nov 2018 13:25:58 +0200 Subject: [PATCH] Fixed handling of tank/map codes not found in the the database --- tanks.json | 3 ++- wotbreplay_uploader.py | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tanks.json b/tanks.json index bbd87eb..d6566c3 100644 --- a/tanks.json +++ b/tanks.json @@ -3297,7 +3297,8 @@ "T32": "T32", "T34_hvy": "T34", "T34_hvy_Freedom": "T34 Independence", - "T37": "T37", + "A94_T37": "T37", + "T37": "T37", "T40": "T40", "T49": "T67", "T49_Rocket": "T49 ATM", diff --git a/wotbreplay_uploader.py b/wotbreplay_uploader.py index f790d8e..2dd7080 100644 --- a/wotbreplay_uploader.py +++ b/wotbreplay_uploader.py @@ -105,9 +105,13 @@ async def mkReplayQ(queue : asyncio.Queue, files : list, title : str): elif os.path.isdir(fn): with os.scandir(fn) as dirEntry: for entry in dirEntry: - if entry.is_file() and (p_replayfile.match(entry.name) != None): - bu.debug(entry.name) - await queue.put(await mkQueueItem(entry.path, title)) + try: + bu.debug('Found: ' + entry.name) + if entry.is_file() and (p_replayfile.match(entry.name) != None): + bu.debug(entry.name) + await queue.put(await mkQueueItem(entry.path, title)) + except Exception as err: + bu.error(str(err)) bu.debug('File added to queue: ' + fn) bu.debug('Finished') return None @@ -198,16 +202,24 @@ def getTitle(replayfile: str, title: str, i : int) -> str: if title == None: try: filename = os.path.basename(replayfile) - # debug(filename) + bu.debug(filename) map_usrStrs = wg.getMapUserStrs() p = re.compile('\\d{8}_\\d{4}_(.+)_(' + '|'.join(map_usrStrs) + ')(?:-\\d)?\\.wotbreplay$') m = p.match(filename) if (m != None): if wg.tanks != None: - tank = wg.tanks['userStr'][m.group(1)] + tank = m.group(1) + if tank in wg.tanks['userStr']: + tank = wg.tanks['userStr'][tank] + else: + bu.error('Tank code: "' + tank + '" not found from Tankopedia (tanks.json)') else: tank = m.group(1) - blitz_map = wg.maps[m.group(2)] + blitz_map = m.group(2) + if blitz_map in wg.maps: + blitz_map = wg.maps[blitz_map] + else: + bu.error('Mapcode: "' + blitz_map + '" not found from map database (maps.json)') title = tank + ' @ ' + blitz_map else: title = re.sub('\\.wotbreplay$', '', filename)