diff --git a/main.py b/main.py index c03e903..5f472fe 100644 --- a/main.py +++ b/main.py @@ -142,6 +142,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 +326,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 = []