mirror of
https://github.com/Jylpah/blitz-tools.git
synced 2026-10-24 19:49:52 +02:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c0de49077 | ||
|
|
07aa7af32f | ||
|
|
ea3306ee6c | ||
|
|
e4882d70af | ||
|
|
433c26d2f8 | ||
|
|
f6b1b1353f |
No files matched your search
+198
-518
File diff suppressed because it is too large.
Load diff
+58
-20
@@ -486,6 +486,16 @@ def NOW() -> int:
|
|||||||
return int(time.time())
|
return int(time.time())
|
||||||
|
|
||||||
|
|
||||||
|
def get_date_str(timestamp:int = NOW(), date_format = '%Y%m%d_%H%M%S'):
|
||||||
|
"""Return YYYYMMDD_HHmm date string"""
|
||||||
|
try:
|
||||||
|
ts = datetime.fromtimestamp(timestamp)
|
||||||
|
return ts.strftime(date_format)
|
||||||
|
except Exception as err:
|
||||||
|
error(exception=err)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def rebase_file_args(current_dir, files):
|
def rebase_file_args(current_dir, files):
|
||||||
"""REbase file command line params after moving working dir to the script's dir"""
|
"""REbase file command line params after moving working dir to the script's dir"""
|
||||||
if isinstance(files, list):
|
if isinstance(files, list):
|
||||||
@@ -916,33 +926,18 @@ class WG:
|
|||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_map(cls, map_str: str) -> str:
|
def get_map(self, map_str: str) -> str:
|
||||||
"""Return map name from short map string in replays"""
|
"""Return map name from short map string in replays"""
|
||||||
try:
|
try:
|
||||||
return cls.maps[map_str]
|
return self.maps[map_str]
|
||||||
except:
|
except:
|
||||||
error('Map ' + map_str + ' not found')
|
error('Map ' + map_str + ' not found')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_map_user_strs(cls) -> str:
|
def get_tank_user_strs(self) -> str:
|
||||||
return cls.maps.keys()
|
return self.tanks["userStr"].keys()
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tank_str2name(cls, tank_str: str) -> str:
|
|
||||||
"""Return tank name from short tank string in replays"""
|
|
||||||
try:
|
|
||||||
return cls.tanks["userStr"][tank_str]
|
|
||||||
except:
|
|
||||||
error('Tank ' + tank_str + ' not found')
|
|
||||||
return tank_str
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_tank_user_strs(cls) -> str:
|
|
||||||
return cls.tanks["userStr"].keys()
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -1079,10 +1074,14 @@ class WG:
|
|||||||
"""Load tanks from tankopedia JSON"""
|
"""Load tanks from tankopedia JSON"""
|
||||||
if tankopedia_fn == None:
|
if tankopedia_fn == None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(tankopedia_fn, 'rt', encoding='utf8') as f:
|
with open(tankopedia_fn, 'rt', encoding='utf8') as f:
|
||||||
self.tanks = json.loads(f.read())
|
self.tanks = json.loads(f.read())
|
||||||
|
self.tanks['tankStr'] = dict()
|
||||||
|
p = re.compile('.+_short$')
|
||||||
|
for usr_str in self.tanks['userStr']:
|
||||||
|
if p.match(usr_str) == None:
|
||||||
|
self.tanks['tankStr'][self.tanks['userStr'][usr_str]] = usr_str
|
||||||
self.tanks_by_tier = dict()
|
self.tanks_by_tier = dict()
|
||||||
for tier in range(1,11):
|
for tier in range(1,11):
|
||||||
self.tanks_by_tier[str(tier)] = list()
|
self.tanks_by_tier[str(tier)] = list()
|
||||||
@@ -1094,6 +1093,43 @@ class WG:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_replay_filename(self, replay: dict):
|
||||||
|
try:
|
||||||
|
summary = replay['data']['summary']
|
||||||
|
timestamp = int(summary['battle_start_timestamp'])
|
||||||
|
timestamp = get_date_str(timestamp, date_format='%Y%m%d_%H%M')
|
||||||
|
player = summary['player_name']
|
||||||
|
arena_id = int(summary['arena_unique_id'])
|
||||||
|
vehicle = self.name2tank_str(summary['vehicle'])
|
||||||
|
vehicle.replace(' ','_')
|
||||||
|
|
||||||
|
return '{:s}_{:s}_{:s}_{:d}.wotbreplay.json'.format(timestamp, player, vehicle, arena_id)
|
||||||
|
except Exception as err:
|
||||||
|
error('Unexpected Exception', err)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_map_user_strs(self) -> str:
|
||||||
|
return self.maps.keys()
|
||||||
|
|
||||||
|
|
||||||
|
def tank_str2name(self, tank_str: str) -> str:
|
||||||
|
"""Return tank name from short tank string in replays"""
|
||||||
|
try:
|
||||||
|
return self.tanks["userStr"][tank_str]
|
||||||
|
except:
|
||||||
|
error('Tank ' + tank_str + ' not found')
|
||||||
|
return tank_str
|
||||||
|
|
||||||
|
|
||||||
|
def name2tank_str(self, name: str) -> str:
|
||||||
|
"""Return shorttank string from tank string in replays"""
|
||||||
|
try:
|
||||||
|
return self.tanks["tankStr"][name]
|
||||||
|
except:
|
||||||
|
debug('Tank ' + name + ' not found')
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
def get_tanks_by_tier(self, tier: int) -> list():
|
def get_tanks_by_tier(self, tier: int) -> list():
|
||||||
"""Returns tank_ids by tier"""
|
"""Returns tank_ids by tier"""
|
||||||
try:
|
try:
|
||||||
@@ -1831,6 +1867,8 @@ class WoTinspector:
|
|||||||
except Exception as err:
|
except Exception as err:
|
||||||
debug(exception=err, id=N)
|
debug(exception=err, id=N)
|
||||||
await asyncio.sleep(SLEEP)
|
await asyncio.sleep(SLEEP)
|
||||||
|
_id = self.read_replay_id(json_resp)
|
||||||
|
json_resp['_id'] = _id
|
||||||
|
|
||||||
debug(' Could not post replay: ' + title, id=N)
|
debug(' Could not post replay: ' + title, id=N)
|
||||||
return json_resp
|
return json_resp
|
||||||
|
|||||||
Reference in new issue
Block a user