Esempio n. 1
0
 def test_search_list_id_in_string(self):
     string = 'https://www.hltv.org/matches/2346047/sprout-vs-ssp-united-pro-series-winter-2020'
     self.assertFalse(
         StringHelper.search_list_id_in_string(list_ids=[123321, 1233211],
                                               string=string))
     self.assertFalse(
         StringHelper.search_list_id_in_string(list_ids=[], string=string))
     self.assertTrue(
         StringHelper.search_list_id_in_string(
             list_ids=[123321, 1233211, 2346047], string=string))
Esempio n. 2
0
 def get_blob_from_url(self, url: str) -> ImageResponseDTO:
     req = requests.get(url, headers=self.headers)
     result = ImageResponseDTO()
     result.blob = req.content
     result.mime = req.headers['content-type']
     result.ext = StringHelper.get_extension_from_url(url)
     result.length = int(req.headers['content-length'])
     return result
    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
Esempio n. 4
0
    def __get_hash_tag_string(match: MatchModel) -> str:
        list_words = [
            match.team_won.title,
            match.team_lose.title,
            match.match_kind.title,
            match.get_team_winner_country_title(),
        ]

        if match.get_team_winner_country_title(
        ) != match.get_team_lose_country_title():
            list_words.append(match.get_team_lose_country_title())

        return ' '.join(map(lambda x: StringHelper.get_hashtag(x), list_words))
    def get_list_of_dto(self, html_matches: list) -> list:
        result = []

        if len(html_matches) == 0:
            return []

        for item in html_matches:
            href = item.find('a', {'class': 'a-reset'})['href']
            match_id = StringHelper.get_match_id_from_url(href)

            if self.match_repository.get_by_hltv_id(match_id):
                continue

            match_dto = self.create_match_dto_from_url.create(href=href)
            match_dto.stars = self._get_count_stars(item)
            match_dto.type = item.find('div', {'class': 'map-text'}).getText()

            if match_dto:
                result.append(match_dto)

        return result
Esempio n. 6
0
 def test_url_parse(self):
     self.assertEqual(
         '.png',
         StringHelper.get_extension_from_url(
             'https://www.hltv.org/img/static/flags/300x200/FR.png'))
Esempio n. 7
0
 def test_get_match_id_from_url(self):
     url = "https://www.hltv.org/matches/2346295/pain-vs-rebirth-dreamhack-open-january-2021-north-america"
     self.assertEqual(2346295, StringHelper.get_match_id_from_url(url))
Esempio n. 8
0
 def test_get_hashtag(self):
     self.assertEqual("#team_x", StringHelper.get_hashtag("team-x"))
     self.assertEqual("#team_x", StringHelper.get_hashtag("team x"))