get_url_JSON(): fix handling of url = None

This commit is contained in:
Jylpah committed 2020-02-13 20:52:54 +02:00
1 parent a349d8ebea
commit 8b3f6d0262
2 files changed
+5 -6

No files matched your search

+1 -1
View File
@@ -335,7 +335,7 @@ class BattleRecordCategory():
def get_headers(self): def get_headers(self):
try: try:
headers = [ RESULT_CAT_HEADER_FRMT.format(result_categories[self.category_name][0]) ] headers = [ RESULT_CAT_HEADER_FRMT.format(result_categories[self.category_name][0]) ]
for field in result_fields.keys(): for field in result_display_fields:
print_format = '{:^' + str(result_fields[field][2]) + 's}' print_format = '{:^' + str(result_fields[field][2]) + 's}'
headers.append(print_format.format(result_fields[field][0])) headers.append(print_format.format(result_fields[field][0]))
return headers return headers
+4 -5
View File
@@ -252,13 +252,15 @@ async def open_JSON(filename: str, chk_JSON_func = None) -> dict:
return None return None
async def get_url_JSON(session: aiohttp.ClientSession, url, chk_JSON_func = None, max_tries = MAX_RETRIES) -> dict: async def get_url_JSON(session: aiohttp.ClientSession, url: str, chk_JSON_func = None, max_tries = MAX_RETRIES) -> dict:
"""Retrieve (GET) an URL and return JSON object""" """Retrieve (GET) an URL and return JSON object"""
if session == None: if session == None:
error('Session must be initialized first') error('Session must be initialized first')
sys.exit(1) sys.exit(1)
if url == None:
return None
## To avoid excessive use of servers ## To avoid excessive use of servers
for retry in range(1,max_tries+1): for retry in range(1,max_tries+1):
try: try:
await asyncio.sleep(SLEEP) await asyncio.sleep(SLEEP)
@@ -830,10 +832,7 @@ class WG:
async def get_player_tank_stats(self, account_id: int, tank_ids = [], fields = [], cache=True) -> dict: async def get_player_tank_stats(self, account_id: int, tank_ids = [], fields = [], cache=True) -> dict:
"""Get player's stats (WR, # of battles) in a tank or all tanks (empty tank_ids[])""" """Get player's stats (WR, # of battles) in a tank or all tanks (empty tank_ids[])"""
# debug('Started')
try: try:
#debug('account_id: ' + str(account_id) + ' TankID: ' + ','.join([ str(id) for id in tank_ids]))
stats = None stats = None
# try cached stats first: # try cached stats first: