class ParseMatchesHTML(LoggerAbstract): http_client_service: HttpClientService = None config: ConfigService = None def __init__(self): super().__init__() self.http_client_service = HttpClientService() self.config = ConfigService() def get_matches(self, page: int = None) -> list: result = [] link = self._get_link(page) text = self.http_client_service.get_html_page(link) self.logger.info(f'Opened {link}') soup = BeautifulSoup(text, "html.parser") if page is None: matches = soup.find_all('div', {'data-zonedgrouping-headline-classes': 'standard-headline'}) matches_list = matches[0].find_all('div', {'class': 'results-sublist'}) for i in range(0, len(matches_list) - 1): result = result + matches_list[i].find_all('div', {'class': 'result-con'}) return result if page: return soup.find_all('div', {'class': 'result-con', 'data-zonedgrouping-entry-unix': True}) def _get_link(self, page: int = None) -> str: offset = '' if page is not None and page > 1: offset = f'?offset={(page - 1) * 100}' return f'{self.config.get_hltv_result_endpoint()}{offset}'
class ImageStorageCreator: storage_client: MinioClient config: ConfigService http_client_service: HttpClientService def __init__(self): self.storage_client = MinioClient() self.config = ConfigService() self.http_client_service = HttpClientService() @strict def create(self, image_url: str, title, folder: str) -> str: image_response_dto = self.http_client_service.get_blob_from_url( image_url) img_title = StringHelper.get_string(title) img_filename = img_title + image_response_dto.ext self.storage_client.upload(folder=folder, image_response_dto=image_response_dto, img_name=img_filename) return img_filename
def __init__(self): self.storage_client = MinioClient() self.config = ConfigService() self.http_client_service = HttpClientService()
def __init__(self): super().__init__() self.http_client_service = HttpClientService() self.config = ConfigService()
def setUp(self) -> None: http_client_service = HttpClientService() html_page = http_client_service.get_html_page( 'https://www.hltv.org/matches/2346036/thedice-vs-game-fist-numberone-season-1' ) self.soup = BeautifulSoup(html_page, "html.parser")
def setUp(self) -> None: self.http_client_service = HttpClientService()
class CreateMatchDTOFromUrl(LoggerAbstract): config: ConfigService = None def __init__(self): super().__init__() self.config = ConfigService() self.http_client_service = HttpClientService() def create(self, href: str): html_page = self.http_client_service.get_html_page( self.config.HLTV_SITE + href) self.logger.info(f'Opened {self.config.HLTV_SITE + href}') soup = BeautifulSoup(html_page, "html.parser") try: teams = soup.find('div', { "class": "standard-box teamsBox" }).find_all("div", {"class": "team"}) except Exception as e: self.logger.error(e, exc_info=True) return None match_dto = self.__create_match_dto(item=soup.find( 'div', {"class": "match-page"}), href=href) for team in teams: team_dto = self.__create_team_dto(team) if team.find("div", {"class": "won"}): match_dto.winner = team_dto elif team.find("div", {"class": "lost"}): match_dto.looser = team_dto time.sleep(1) return match_dto def __create_team_dto(self, team) -> TeamDTO: team_dto = TeamDTO() team_dto.score = team.find("div", {"class": ["won", "lost"]}).getText() team_dto.title = team.find("img", {"class": "logo"}).get('title') team_dto.country = team.find("img", { "class": ["team1", "team2"] }).get('title') team_dto.country_image_url = team.find("img", { "class": ["team1", "team2"] }).get('src') team_dto.set_image_url(team.find("img", {"class": "logo"}).get('src')) return team_dto def __create_match_dto(self, item, href: str) -> MatchDTO: match_dto = MatchDTO() match_dto.id = self._get_id(href) match_dto.href = self.config.HLTV_SITE + href match_dto.type = self.get_type( item.find('div', { 'class': 'veto-box' }).getText()) match_dto.event = item\ .find('div', {'class': 'timeAndEvent'})\ .find('div', {'class': 'text-ellipsis'})\ .find('a').getText() unix_time = item.find('div', { 'class': 'timeAndEvent' }).find('div', {'class': 'date'})['data-unix'] match_dto.played_at = DateTimeHelper.unix_time_to_datetime( int(unix_time)) return match_dto @staticmethod def _get_id(string: str) -> int: data = string.split("/")[2] return int(data) @staticmethod def get_type(string: str) -> str: type_map = { 'Best of 1': 'bo1', 'Best of 3': 'bo3', 'Best of 5': 'bo5', } for k, v in type_map.items(): if string.find(k) != -1: return v return 'bo3'