diff --git a/matches.py b/matches.py index d7f00b9..232fea1 100644 --- a/matches.py +++ b/matches.py @@ -1,23 +1,18 @@ import opendota +import datetime +import players +import utils match_client = opendota.MatchesApi() -def serialize_player(player): - player_data = { - 'personaname': player.personaname, - 'kills': player.kills, - 'deaths': player.deaths, - 'assists': player.assists, - 'total_gold': player.total_gold, - 'last_hits': player.last_hits, - 'denies': player.denies, - } - return player_data - def serialize_match(match_id): match = match_client.get_matches_by_match_id(match_id) match_data = { - 'players': [serialize_player(player) for player in match.players], + 'players': [players.serialize_player(player) for player in match.players], + 'dire_score': match.dire_score, + 'radiant_score': match.radiant_score, + 'start_time': datetime.datetime.fromtimestamp(match.start_time).strftime('%Y-%m-%d %H:%M:%S'), + 'duration': '%d:%02d:%02d' % utils.convert_seconds_to_hms(match.duration), + 'radiant_win': match.radiant_win, } return match_data - diff --git a/players.py b/players.py new file mode 100644 index 0000000..f7b28e1 --- /dev/null +++ b/players.py @@ -0,0 +1,15 @@ +def serialize_player(player): + player_data = { + 'personaname': player.personaname, + 'kills': player.kills, + 'deaths': player.deaths, + 'assists': player.assists, + 'total_gold': player.total_gold, + 'last_hits': player.last_hits, + 'denies': player.denies, + 'party_id': player.party_id, + 'win': player.win, + 'level': player.level, + 'is_radiant': player.is_radiant, + } + return player_data diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..420c4ab --- /dev/null +++ b/utils.py @@ -0,0 +1,4 @@ +def convert_seconds_to_hms(total_seconds): + hours, remainder = divmod(total_seconds, 3600) + minutes, seconds = divmod(remainder, 60) + return hours, minutes, seconds