mirror of
https://github.com/SocksPls/hltv-api
synced 2025-05-02 00:09:34 +00:00
Compare commits
7 commits
1390409c08
...
6a164b071a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6a164b071a | ||
![]() |
b260a406fc | ||
![]() |
3dca12d78e | ||
![]() |
d8daf95b3d | ||
![]() |
1671d93c24 | ||
![]() |
4b6cde2cf6 | ||
![]() |
54dc744189 |
2 changed files with 66 additions and 158 deletions
172
README.md
172
README.md
|
@ -10,10 +10,7 @@ Provides an API for HLTV
|
|||
[{'id': 4608,
|
||||
'name': 'Natus Vincere',
|
||||
'url': 'https://hltv.org/team/4608/natus-vincere'},
|
||||
{'id': 6667, 'name': 'FaZe', 'url': 'https://hltv.org/team/6667/faze'},
|
||||
{'id': 4869, 'name': 'ENCE', 'url': 'https://hltv.org/team/4869/ence'},
|
||||
{'id': 5752, 'name': 'Cloud9', 'url': 'https://hltv.org/team/5752/cloud9'},
|
||||
{'id': 9565, 'name': 'Vitality', 'url': 'https://hltv.org/team/9565/vitality'}]
|
||||
...]
|
||||
```
|
||||
|
||||
## `top30teams`
|
||||
|
@ -28,18 +25,7 @@ Provides an API for HLTV
|
|||
'team-players': [{'name': "Aleksandr 's1mple' Kostyliev",
|
||||
'player-id': 7998,
|
||||
'url': 'https://www.hltv.org/player/7998/s1mple'},
|
||||
{'name': "Denis 'electroNic' Sharipov",
|
||||
'player-id': 8918,
|
||||
'url': 'https://www.hltv.org/player/8918/electronic'},
|
||||
{'name': "Viktor 'sdy' Orudzhev",
|
||||
'player-id': 12731,
|
||||
'url': 'https://www.hltv.org/player/12731/sdy'},
|
||||
{'name': "Ilya 'Perfecto' Zalutskiy",
|
||||
'player-id': 16947,
|
||||
'url': 'https://www.hltv.org/player/16947/perfecto'},
|
||||
{'name': "Valeriy 'b1t' Vakhovskiy",
|
||||
'player-id': 18987,
|
||||
'url': 'https://www.hltv.org/player/18987/b1t'}],
|
||||
...],
|
||||
'team-url': 'https://hltv.org/team/4608/Natus Vincere'},
|
||||
...
|
||||
]
|
||||
|
@ -68,22 +54,7 @@ Provides an API for HLTV
|
|||
'name': "Andreas 'Xyp9x' Højsleth",
|
||||
'nickname': 'Xyp9x',
|
||||
'url': 'https://hltv.org/player/4954/xyp9x'},
|
||||
{'id': 7412,
|
||||
'name': "Lukas 'gla1ve' Rossander",
|
||||
'nickname': 'gla1ve',
|
||||
'url': 'https://hltv.org/player/7412/gla1ve'},
|
||||
{'id': 9078,
|
||||
'name': "Kristian 'k0nfig' Wienecke",
|
||||
'nickname': 'k0nfig',
|
||||
'url': 'https://hltv.org/player/9078/k0nfig'},
|
||||
{'id': 13300,
|
||||
'name': "Asger 'Farlig' Jensen",
|
||||
'nickname': 'Farlig',
|
||||
'url': 'https://hltv.org/player/13300/farlig'},
|
||||
{'id': 15165,
|
||||
'name': "Benjamin 'blameF' Bremer",
|
||||
'nickname': 'blameF',
|
||||
'url': 'https://hltv.org/player/15165/blamef'}]
|
||||
...]
|
||||
```
|
||||
|
||||
## `get_team_info`
|
||||
|
@ -96,138 +67,23 @@ Provides an API for HLTV
|
|||
'name': 'Andreas Højsleth',
|
||||
'nickname': 'Xyp9x',
|
||||
'url': 'https://hltv.org/stats/players/4954/xyp9x'},
|
||||
{'country': 'Denmark',
|
||||
'id': 7412,
|
||||
'maps-played': 1094,
|
||||
'name': 'Lukas Rossander',
|
||||
'nickname': 'gla1ve',
|
||||
'url': 'https://hltv.org/stats/players/7412/gla1ve'},
|
||||
{'country': 'Denmark',
|
||||
'id': 9078,
|
||||
'maps-played': 139,
|
||||
'name': 'Kristian Wienecke',
|
||||
'nickname': 'k0nfig',
|
||||
'url': 'https://hltv.org/stats/players/9078/k0nfig'},
|
||||
{'country': 'Denmark',
|
||||
'id': 13300,
|
||||
'maps-played': 82,
|
||||
'name': 'Asger Jensen',
|
||||
'nickname': 'Farlig',
|
||||
'url': 'https://hltv.org/stats/players/13300/farlig'},
|
||||
{'country': 'Denmark',
|
||||
'id': 15165,
|
||||
'maps-played': 139,
|
||||
'name': 'Benjamin Bremer',
|
||||
'nickname': 'blameF',
|
||||
'url': 'https://hltv.org/stats/players/15165/blamef'}],
|
||||
...],
|
||||
'historical-players': [{'country': 'Denmark',
|
||||
'id': 9612,
|
||||
'maps-played': 86,
|
||||
'name': 'Lucas Andersen',
|
||||
'nickname': 'Bubzkji',
|
||||
'url': 'https://hltv.org/stats/players/9612/bubzkji'},
|
||||
{'country': 'Denmark',
|
||||
'id': 9612,
|
||||
'maps-played': 86,
|
||||
'name': 'Lucas Andersen',
|
||||
'nickname': 'Bubzkji',
|
||||
'url': 'https://hltv.org/stats/players/9612/bubzkji'},
|
||||
{'country': 'Denmark',
|
||||
'id': 7592,
|
||||
'maps-played': 1076,
|
||||
'name': 'Nicolai Reedtz',
|
||||
'nickname': 'device',
|
||||
'url': 'https://hltv.org/stats/players/7592/device'},
|
||||
{'country': 'Denmark',
|
||||
'id': 7398,
|
||||
'maps-played': 1179,
|
||||
'name': 'Peter Rasmussen',
|
||||
'nickname': 'dupreeh',
|
||||
'url': 'https://hltv.org/stats/players/7398/dupreeh'},
|
||||
{'country': 'Denmark',
|
||||
'id': 8611,
|
||||
'maps-played': 53,
|
||||
'name': 'Patrick Hansen',
|
||||
'nickname': 'es3tag',
|
||||
'url': 'https://hltv.org/stats/players/8611/es3tag'},
|
||||
{'country': 'Denmark',
|
||||
'id': 429,
|
||||
'maps-played': 185,
|
||||
'name': 'Finn Andersen',
|
||||
'nickname': 'karrigan',
|
||||
'url': 'https://hltv.org/stats/players/429/karrigan'},
|
||||
{'country': 'Denmark',
|
||||
'id': 8394,
|
||||
'maps-played': 355,
|
||||
'name': 'Markus Kjærbye',
|
||||
'nickname': 'Kjaerbye',
|
||||
'url': 'https://hltv.org/stats/players/8394/kjaerbye'},
|
||||
{'country': 'Denmark',
|
||||
'id': 9032,
|
||||
'maps-played': 732,
|
||||
'name': 'Emil Reif',
|
||||
'nickname': 'Magisk',
|
||||
'url': 'https://hltv.org/stats/players/9032/magisk'},
|
||||
{'country': 'Denmark',
|
||||
'id': 21,
|
||||
'maps-played': 12,
|
||||
'name': 'Danny Sørensen',
|
||||
'nickname': 'zonic',
|
||||
'url': 'https://hltv.org/stats/players/21/zonic'},
|
||||
{'country': 'Denmark',
|
||||
'id': 2469,
|
||||
'maps-played': 90,
|
||||
'name': 'René Borg',
|
||||
'nickname': 'cajunb',
|
||||
'url': 'https://hltv.org/stats/players/2469/cajunb'},
|
||||
{'country': 'Denmark',
|
||||
'id': 13843,
|
||||
'maps-played': 103,
|
||||
'name': 'Philip Ewald',
|
||||
'nickname': 'Lucky',
|
||||
'url': 'https://hltv.org/stats/players/13843/lucky'},
|
||||
{'country': 'Norway',
|
||||
'id': 1485,
|
||||
'maps-played': 10,
|
||||
'name': 'Ruben Villarroel',
|
||||
'nickname': 'RUBINO',
|
||||
'url': 'https://hltv.org/stats/players/1485/rubino'},
|
||||
{'country': 'Denmark',
|
||||
'id': 16718,
|
||||
'maps-played': 1,
|
||||
'name': 'Frederik Sørensen',
|
||||
'nickname': 'Fessor',
|
||||
'url': 'https://hltv.org/stats/players/16718/fessor'},
|
||||
{'country': 'Denmark',
|
||||
'id': 9903,
|
||||
'maps-played': 4,
|
||||
'name': 'Anton Pedersen',
|
||||
'nickname': 'notaN',
|
||||
'url': 'https://hltv.org/stats/players/9903/notan'},
|
||||
{'country': 'Denmark',
|
||||
'id': 8783,
|
||||
'maps-played': 15,
|
||||
'name': 'Jakob Hansen',
|
||||
'nickname': 'JUGi',
|
||||
'url': 'https://hltv.org/stats/players/8783/jugi'},
|
||||
{'country': 'Denmark',
|
||||
'id': 7154,
|
||||
'maps-played': 4,
|
||||
'name': 'Jacob Winneche',
|
||||
'nickname': 'Pimp',
|
||||
'url': 'https://hltv.org/stats/players/7154/pimp'},
|
||||
{'country': 'Denmark',
|
||||
'id': 922,
|
||||
'maps-played': 9,
|
||||
'name': 'Marco Pfeiffer',
|
||||
'nickname': 'Snappi',
|
||||
'url': 'https://hltv.org/stats/players/922/snappi'},
|
||||
{'country': 'Sweden',
|
||||
'id': 1146,
|
||||
'maps-played': 8,
|
||||
'name': 'Dennis Edman',
|
||||
'nickname': 'dennis',
|
||||
'url': 'https://hltv.org/stats/players/1146/dennis'}],
|
||||
...],
|
||||
'matches': [{'championship': 'BLAST Premier Fall Groups 2022',
|
||||
'confront_name': 'Astralis X Ninjas in Pyjamas',
|
||||
'date': '2022-08-19',
|
||||
'teams': {'team_1': 'Astralis',
|
||||
'team_1_id': 6665,
|
||||
'team_2': 'Ninjas in Pyjamas',
|
||||
'team_2_id': 4411},
|
||||
'time': '14:00'},
|
||||
...]
|
||||
'stats': {'K/D Ratio': '1.10',
|
||||
'Maps played': '1323',
|
||||
'Rounds played': '34752',
|
||||
|
|
52
main.py
52
main.py
|
@ -43,6 +43,7 @@ def _monthNameToNumber(monthName: str):
|
|||
'June': 6,
|
||||
'July': 7,
|
||||
'August': 8,
|
||||
'Augu': 8,
|
||||
'September': 9,
|
||||
'October': 10,
|
||||
'November': 11,
|
||||
|
@ -142,6 +143,17 @@ def get_team_info(teamid):
|
|||
|
||||
team_info['team-id'] = _findTeamId(page.find("div", {"class": "context-item"}).text)
|
||||
|
||||
match_page = get_parsed_page("https://www.hltv.org/team/" + str(teamid) +
|
||||
"/" + str(team_info['team-name']) + "#tab-matchesBox")
|
||||
has_not_upcomming_matches = match_page.find(
|
||||
"div", {"class": "empty-state"})
|
||||
if has_not_upcomming_matches:
|
||||
team_info['matches'] = []
|
||||
else:
|
||||
match_table = match_page.find(
|
||||
"table", {"class": "table-container match-table"})
|
||||
team_info['matches'] = _get_matches_by_team(match_table)
|
||||
|
||||
current_lineup = _get_current_lineup(page.find_all("div", {"class": "col teammate"}))
|
||||
team_info['current-lineup'] = current_lineup
|
||||
|
||||
|
@ -315,6 +327,46 @@ def get_results():
|
|||
|
||||
return results_list
|
||||
|
||||
def _get_matches_by_team(table):
|
||||
events = table.find_all("tr", {"class": "event-header-cell"})
|
||||
event_matches = table.find_all("tbody")
|
||||
matches = []
|
||||
for i, event in enumerate(events):
|
||||
|
||||
event_name = event.find("a", {"class": "a-reset"}).text
|
||||
rows = event_matches[i]("tr", {"class": "team-row"})
|
||||
|
||||
for row in rows[0:len(rows)]:
|
||||
match = {}
|
||||
dateArr = (row.find(
|
||||
"td", {"class": "date-cell"}).find("span").text).split('/')
|
||||
|
||||
dateTextFromArrPadded = _padIfNeeded(dateArr[2]) + "-" + _padIfNeeded(dateArr[1]) + "-" + _padIfNeeded(dateArr[0])
|
||||
|
||||
dateFromHLTV = datetime.datetime.strptime(dateTextFromArrPadded,'%Y-%m-%d').replace(tzinfo=HLTV_ZONEINFO)
|
||||
dateFromHLTV = dateFromHLTV.astimezone(LOCAL_ZONEINFO)
|
||||
|
||||
date = dateFromHLTV.strftime('%Y-%m-%d')
|
||||
match['date'] = date
|
||||
match['teams'] = {}
|
||||
match['teams']["team_1"] = row.find(
|
||||
"td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"}).text
|
||||
match['teams']["team_1_id"] = _findTeamId(row.find( "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"}).text)
|
||||
match['teams']["team_2"] = row.find(
|
||||
"td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"}).text
|
||||
match['teams']["team_2_id"] = _findTeamId(row.find( "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"}).text)
|
||||
match["confront_name"] = match['teams']["team_1"] + \
|
||||
" X " + match['teams']["team_2"]
|
||||
match["championship"] = event_name
|
||||
match_url = row.find(
|
||||
"td", {"class": "matchpage-button-cell"}).find("a")['href']
|
||||
match['time'] = get_parsed_page("https://www.hltv.org" + match_url).find(
|
||||
'div', {"class": "timeAndEvent"}).find('div', {"class": "time"}).text
|
||||
matches.append(match)
|
||||
|
||||
return matches
|
||||
|
||||
|
||||
def get_results_by_date(start_date, end_date):
|
||||
# Dates like yyyy-mm-dd (iso)
|
||||
results_list = []
|
||||
|
|
Loading…
Add table
Reference in a new issue