From 54dc7441891bccd99a146fdd6134534872d30e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?CA=C3=ADque=20-?= Date: Sun, 14 Aug 2022 01:31:20 -0300 Subject: [PATCH 1/3] matches by team --- main.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/main.py b/main.py index c03e903..8caf551 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,41 @@ 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 = {} + match['date'] = row.find( + "td", {"class": "date-cell"}).find("span").text + 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"] = row.find( + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"})['href'].split('/')[2] + match['teams']["team_2"] = row.find( + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"}).text + match['teams']["team_2_id"] = row.find( + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"})['href'].split('/')[2] + 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 + match['full_time'] = match['date'] + ' at ' + match['time'] + matches.append(match) + + return matches + + def get_results_by_date(start_date, end_date): # Dates like yyyy-mm-dd (iso) results_list = [] From 4b6cde2cf6a1427d9d6d5a151aa0f230f9935265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?CA=C3=ADque=20-?= Date: Sun, 14 Aug 2022 01:37:45 -0300 Subject: [PATCH 2/3] fix docefactor --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 8caf551..a54fd33 100644 --- a/main.py +++ b/main.py @@ -332,22 +332,22 @@ def _get_matches_by_team(table): matches = [] for i, event in enumerate(events): - event_name = event.find("a", {"class": "a-reset"}).text + 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 = {} match['date'] = row.find( - "td", {"class": "date-cell"}).find("span").text + "td", {"class": "date-cell"}).find("span").text match['teams'] = {} match['teams']["team_1"] = row.find( - "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"}).text + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"}).text match['teams']["team_1_id"] = row.find( - "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"})['href'].split('/')[2] + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"})['href'].split('/')[2] match['teams']["team_2"] = row.find( - "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"}).text + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"}).text match['teams']["team_2_id"] = row.find( - "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"})['href'].split('/')[2] + "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"})['href'].split('/')[2] match["confront_name"] = match['teams']["team_1"] + \ " X " + match['teams']["team_2"] match["championship"] = event_name From 1671d93c245a8df501557ac8c7629a48d5402268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?CA=C3=ADque=20-?= Date: Sun, 14 Aug 2022 16:05:55 -0300 Subject: [PATCH 3/3] resolve PR to pattern --- main.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index a54fd33..5f472fe 100644 --- a/main.py +++ b/main.py @@ -337,17 +337,23 @@ def _get_matches_by_team(table): for row in rows[0:len(rows)]: match = {} - match['date'] = row.find( - "td", {"class": "date-cell"}).find("span").text + 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"] = row.find( - "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-1"})['href'].split('/')[2] + 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"] = row.find( - "td", {"class": "team-center-cell"}).find("a", {"class": "team-name team-2"})['href'].split('/')[2] + 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 @@ -355,7 +361,6 @@ def _get_matches_by_team(table): "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 - match['full_time'] = match['date'] + ' at ' + match['time'] matches.append(match) return matches