From 203d30a8c6ce8ccc001ab1a5efbf55b75e686681 Mon Sep 17 00:00:00 2001 From: Ching Date: Wed, 6 Mar 2024 11:01:04 +0800 Subject: [PATCH] feat: Add end time to Match class --- dota.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dota.py b/dota.py index 64fd016..589d7ae 100644 --- a/dota.py +++ b/dota.py @@ -61,6 +61,7 @@ class Match(BaseModel): 'radiant_score': match_.radiant_score, # isoformat utc+8 'start_time': datetime.datetime.fromtimestamp(match_.start_time).strftime('%Y-%m-%dT%H:%M:%S.000+08:00'), + 'end_time': datetime.datetime.fromtimestamp(match_.start_time + match_.duration).strftime('%Y-%m-%dT%H:%M:%S.000+08:00'), 'duration': '%d:%02d:%02d' % utils.convert_seconds_to_hms(match_.duration), 'radiant_win': match_.radiant_win, 'party_size': self.party_size, @@ -97,6 +98,7 @@ class Friend(BaseModel): 'assists': match_.assists, 'party_size': match_.party_size, 'start_time': match_.start_time, + 'end_time': match_.start_time + match_.duration, 'duration': match_.duration, 'average_rank': utils.get_ranking(match_.average_rank), 'hero_id': match_.hero_id, @@ -142,14 +144,15 @@ class Friend(BaseModel): if match_['average_rank']: summary += '\n' + match_['average_rank'] - start_time = datetime.datetime.fromtimestamp(match_['start_time']).strftime('%Y-%m-%dT%H:%M:%S.000+08:00') + # start_time = datetime.datetime.fromtimestamp(match_['start_time']).strftime('%Y-%m-%dT%H:%M:%S.000+08:00') + end_time = datetime.datetime.fromtimestamp(match_['end_time']).strftime('%Y-%m-%dT%H:%M:%S.000+08:00') hero_name = Hero.get(hero_id=match_['hero_id']).localized_name data['embeds'].append({ 'title': f"{hero_name} {match_['kills']} 杀 {match_['deaths']} 死 {match_['assists']} 助 ", 'description': summary, 'color': 6732650 if match_['win'] else 16724787, # 66bb6a or FF3333 'fields': [], - 'timestamp': start_time, + 'timestamp': end_time, 'url': f"https://www.opendota.com/matches/{match_['match_id']}", }) return data @@ -295,7 +298,7 @@ def serialize_match_for_discord(match_): "name": "opendota", "url": "https://www.opendota.com/matches/%s" % match_['match_id'] }, - "timestamp": match_['start_time'] + "timestamp": match_['end_time'] } ], }