1
0
Fork 0
mirror of https://github.com/SocksPls/hltv-api synced 2025-04-30 15:43:07 +00:00

Added stats to get_player_info

This commit is contained in:
socks 2020-11-10 13:29:31 +00:00
parent 5a69533427
commit 8cbeac756e
2 changed files with 33 additions and 2 deletions

View file

@ -59,7 +59,21 @@ Provides an API for HLTV
'name': b'Peter Rasmussen',
'country': 'Denmark',
'team': b'Astralis',
'age': '27'}
'age': '27',
'stats': {'total_kills': '32442',
'headshot_percent': '50.6%',
'total_deaths': '28386',
'kd_ratio': '1.14',
'dmg_per_round': '78.2',
'grenade_dmg_per_round': '3.0',
'maps_played': '1690',
'rounds_played': '43830',
'kills_per_round': '0.74',
'assists_per_round': '0.14',
'deaths_per_round': '0.65',
'saved_by_teammate_per_round': '0.10',
'saved_teammates_per_round': '0.09',
'rating_1': '1.09'}}
```
## `get_team_info`

19
main.py
View file

@ -84,12 +84,29 @@ def get_player_info(player_id):
"""
page = get_parsed_page(f"https://www.hltv.org/stats/players/{player_id}/a")
statistics = page.find("div", {"class": "statistics"}).find_all("div", {"class": "stats-row"})
player_info = {
'nickname': page.find("h1", {"class": "summaryNickname text-ellipsis"}).text.encode('utf8'),
'name': page.find("div", {"class": "text-ellipsis"}).text[1:-1].encode('utf8'),
'country': page.find("img", {"class": "flag"})["alt"],
'team': page.find("a", {"class": "a-reset text-ellipsis"}).text.encode('utf8'),
'age': page.find("div", {"class": "summaryPlayerAge"}).text[:2]
'age': page.find("div", {"class": "summaryPlayerAge"}).text[:2],
'stats': {
'total_kills': statistics[0].find_all("span")[1].text,
'headshot_percent': statistics[1].find_all("span")[1].text,
'total_deaths': statistics[2].find_all("span")[1].text,
'kd_ratio': statistics[3].find_all("span")[1].text,
'dmg_per_round': statistics[4].find_all("span")[1].text,
'grenade_dmg_per_round': statistics[5].find_all("span")[1].text,
'maps_played': statistics[6].find_all("span")[1].text,
'rounds_played': statistics[7].find_all("span")[1].text,
'kills_per_round': statistics[8].find_all("span")[1].text,
'assists_per_round': statistics[9].find_all("span")[1].text,
'deaths_per_round': statistics[10].find_all("span")[1].text,
'saved_by_teammate_per_round': statistics[11].find_all("span")[1].text,
'saved_teammates_per_round': statistics[12].find_all("span")[1].text,
'rating_1': statistics[13].find_all("span")[1].text,
}
}
return player_info