Exemple #1
0
    def _get_matches_info(self, match_elements, championship_urls):
        matches = []
        base_len = len(OneXBetScraper._BASE_URL)

        for match_element in list(match_elements)[:]:
            try:
                url = match_element.get_attribute('href')[base_len:]
            except StaleElementReferenceException:
                print('Caught StaleElementReferenceException')
                continue

            if url in championship_urls or match_element.get_attribute(
                    'class') != 'link' or url.endswith('-Special-bets/'):
                continue

            match_title_text = match_element.find_element_by_class_name(
                'gname').text
            match_title = MatchTitle.from_str(match_title_text)
            date_time_str = match_element.find_element_by_class_name(
                'date').text
            try:
                date_time = DateTime.from_1xbet_str(date_time_str)
            except ValueError:
                print(url)
                continue
            match = Match(match_title, self._BASE_URL + url, date_time, self)
            matches.append(match)

        return matches
 def _get_match_basic_data(self, event):
     date = event.find_element_by_class_name('event--date').text
     time = event.find_element_by_class_name('event--time').text
     date_time_str = date + time
     date_time = DateTime.from_favorit_str(date_time_str)
     name = event.find_element_by_class_name('long--name').text.lower()
     button = event.find_element_by_class_name('event--more')
     self.renderer.click(button)
     url = self.renderer.current_url
     return Match(MatchTitle(name.split(' - ')), url, date_time, self)
Exemple #3
0
 def _get_match_basic_data(self, match):
     date_time_str = match.find_element_by_class_name('date').text
     date_time = DateTime.from_marathon_str(date_time_str)
     url = match.find_element_by_class_name('member-link').get_attribute(
         'href')
     teams = [
         el.text for el in match.find_elements_by_tag_name('span')
         if el.get_attribute('data-member-link')
     ]
     return Match(MatchTitle(teams), url, date_time, self)
Exemple #4
0
 def test_good_init_3(self):
     dt = DateTime.from_dict({
         'year': 2005,
         'month': 7,
         'day': 14,
         'hour': 12,
         'minute': 30,
         'second': 10
     })
     self.assertIsInstance(dt, DateTime)
    def create_programme(self, programme):
        cer = programme["cod_evento_rejilla"]

        if cer in self.cache:
            return self.cache.get(cer)

        info = {
            "channel": programme["cod_cadena_tv"],
            "title": programme["des_evento_rejilla"],
            "category": programme["des_genero"],
            "start": DateTime().parse(programme["f_evento_rejilla"]),
            "stop": DateTime().parse(programme["f_fin_evento_rejilla"])
        }

        cee = programme["cod_elemento_emision"]
        if cee and DOWNLOAD_EXTRA_INFO:
            info.update(Movistar.get_extra_info(cee))

        # DAYS_TO_DOWNLOAD + 1 we add the day before data | 86400 seconds in a day
        expire_time = (DAYS_TO_DOWNLOAD + 1) * 86400
        self.cache.set(cer, info, expire=expire_time)

        return info
Exemple #6
0
    def _get_championship_matches_info(self, url):
        soup = self._get_soup(url)
        matches = []
        bks = self._get_bks(soup)

        for bk in bks:
            match_title = ParimatchScraper._get_match_title(bk)
            date_time_str = ParimatchScraper._get_match_date_time_str(bk)
            date_time = DateTime.from_parimatch_str(date_time_str)
            match = Match(match_title, url, date_time, self)
            match.id = bk.find(class_='no').text
            matches.append(match)

        return matches
Exemple #7
0
    def from_dict(cls, match_dict):
        url = None
        date_time = None
        title = None
        key = list(match_dict.keys())[0]
        found = re.search(r'^(https://.+?) (.+?): (.+?)$', key)
        if found:
            url = found.group(1)
            date_time = DateTime.fromisoformat(found.group(2))
            title = MatchTitle.from_str(found.group(3))

        bets_dict = list(match_dict.values())[0][0]
        bets = [
            Bet.from_dict({bet_title: odds})
            for bet_title, odds in bets_dict.items()
        ]

        return cls(title, url, date_time, None, bets)
Exemple #8
0
 def set_post(self,
              title="",
              category="",
              describes="",
              id="",
              tag="",
              content="",
              datetime=DateTime()):
     self.title = title
     self.category = category
     self.describes = describes
     self.id = id
     if type(tag) == str:
         self.tag = convert_str_to_array(tag).copy()
     elif type(tag) == list:
         self.tag = tag[:]
     self.content = content
     self.date = datetime
Exemple #9
0
 def __init__(self,
              title="",
              category="",
              describes="",
              id="",
              tag="",
              content="",
              times=0,
              datetime=DateTime()):
     self.title = title
     self.category = category
     self.describes = describes
     self.id = id
     if type(tag) is str:
         self.tag = convert_str_to_array(tag).copy()
     elif type(tag) is list:
         self.tag = tag.copy()
     self.content = content
     self.date = datetime
     self.times = times
 def get_matches_info_sport(self, sport_name):
     matches = []
     subsections = self.get_tournaments(sport_name)
     for subsection in subsections:
         # if not LIVE:
         try:
             self.renderer.click(subsection)
         except StaleElementReferenceException:
             continue
         # print(' ', subsections.index(subsection) + 1)
         time.sleep(2)
         events = self.renderer.find_elements_by_class_name(
             'sportEventRow__body___3Ywcg')
         time.sleep(2)
         for event in events:
             try:
                 event.find_element_by_class_name(
                     'matchDateTime__isLive___8f4IP')
                 continue  # match is live
             except NoSuchElementException:
                 pass
             except StaleElementReferenceException:
                 continue
             date_text = event.find_element_by_class_name(
                 'matchDateTime__date___2Hw-c').text
             teams_webel = event.find_elements_by_class_name(
                 '__app-LogoTitle-wrapper')
             teams = [el.text for el in teams_webel]
             url = teams_webel[0].find_element_by_tag_name(
                 'a').get_attribute('href')
             date = DateTime.from_ggbet_str(date_text)
             matches.append(Match(MatchTitle(teams), url, date, self))
         # if not LIVE:
         self.renderer.click(subsection)
     print(len(matches))
     return Sport(sport_name, matches)
 def test_not_equal_day(self):
     assert DateTime(0, 0, 0) != DateTime(1, 0, 0)
 def test_not_equal(self):
     assert DateTime(0, 0, 0) != DateTime(0, 1, 0)
 def test_equal_day(self):
     assert DateTime(1, 0, 0) == DateTime(1, 0, 0)
 def test_greater_minute(self):
     assert DateTime(0, 0, 0) < DateTime(0, 0, 1)
 def test_good7(self):
   self.stamp = DateTime.check_timestamp("25/12/2013")
   correct_stamp = datetime(2013, 12, 25, 23, 59)
   self.assertEqual( correct_stamp, self.stamp)
 def test_not_greater_equal_day(self):
     assert not DateTime(1, 0, 0) <= DateTime(0, 0, 0)
 def test_in_range(self):
     sut = DateRange(DateTime(3, 22, 0), DateTime(3, 24, 0))
     assert sut.in_range(DateTime(3, 23, 0))
 def test_bad2(self):
   self.stamp = DateTime.check_timestamp("2014wuityhwo")
   correct_stamp = datetime(2014, 1, 1, 00, 00)
   self.assertEqual( correct_stamp, self.stamp)
 def test_bad1(self):
   self.stamp = DateTime.check_timestamp("$£%^H2ivoy0")
   correct_stamp = datetime(1111, 1, 1, 00, 00)
   self.assertEqual( correct_stamp, self.stamp)
Exemple #20
0
 def test_good_not_equal(self):
     dt_1 = DateTime()
     dt_2 = DateTime(second=800)
     self.assertNotEqual(dt_1, dt_2)
 def test_bad4(self):
   self.stamp = DateTime.check_timestamp("11/23/08")
   correct_stamp = datetime(2008, 11, 23, 1, 00)
   self.assertEqual( correct_stamp, self.stamp)
Exemple #22
0
 def test_bad_not_equal(self):
     dt_1 = DateTime()
     dt_2 = DateTime()
     self.assertEqual(dt_1, dt_2)
Exemple #23
0
 def test_good_equal(self):
     dt_1 = DateTime()
     dt_2 = DateTime()
     self.assertEqual(dt_1, dt_2)
 def test_middle5(self):
   self.stamp = DateTime.check_timestamp("2013/02/30")
   correct_stamp = datetime(2013, 2, 28, 23, 59)
   self.assertEqual( correct_stamp, self.stamp)
 def test_greater_day(self):
     assert DateTime(0, 0, 0) < DateTime(1, 0, 0)
 def test_vbad0(self):
   self.stamp = DateTime.check_timestamp("iutoeht")
   correct_stamp = datetime(1111, 1, 1, 00, 00)
   self.assertEqual( correct_stamp, self.stamp)
 def test_greater_hour(self):
     assert DateTime(0, 0, 0) < DateTime(0, 1, 0)
 def test_not_greater_equal_hour(self):
     assert not DateTime(0, 2, 0) <= DateTime(0, 1, 0)
 def test_not_greater_day(self):
     assert not DateTime(2, 0, 0) < DateTime(1, 0, 0)
 def test_not_greater_equal_minute(self):
     assert not DateTime(0, 0, 2) <= DateTime(0, 0, 1)
 def test_not_in_range(self):
     sut = DateRange(DateTime(0, 0, 0), DateTime(0, 1, 0))
     assert not sut.in_range(DateTime(0, 2, 0))
 def test_equal(self):
     assert DateTime(0, 0, 0) == DateTime(0, 0, 0)
        while True:
            s = SequenceMatcher(None, first_team, second_team)
            substring = s.find_longest_match(0, len(first_team), 0,
                                             len(second_team))
            if substring.size < min(3, min_initial_length):
                break
            substrings_total_length += substring.size
            # print(first_team[substring.a:substring.b])
            first_team = first_team[:substring.a] + first_team[substring.a +
                                                               substring.size:]
            second_team = second_team[:substring.
                                      b] + second_team[substring.b +
                                                       substring.size:]

        similarity = substrings_total_length / min_initial_length + \
                     (substrings_total_length - max_initial_length) / (10 * max_initial_length)
        return similarity


if __name__ == '__main__':
    certainty = 0.5
    comparator = MatchComparator()
    m1 = Match(MatchTitle(['jd gaming', 'team we']), '123',
               DateTime(2020, 12, 26, 12, 30), 1, [])
    m2 = Match(MatchTitle(['jd', 'we']), '321', DateTime(2020, 12, 26, 13), 2,
               [])
    similarity = comparator.calculate_matches_similarity(m1, m2, certainty)
    print(similarity)
    print(comparator.similar(m1, m2, certainty))
    print(comparator.similarities)
 def test_good8(self):
   self.stamp = DateTime.check_timestamp("25-12-2013")
   correct_stamp = datetime(2013, 12, 25, 00, 59)
   self.assertEqual( correct_stamp, self.stamp)
Exemple #35
0
 def set_date(self, datetime=DateTime()):
     self.date = datetime
 def test_less_hour(self):
     assert DateTime(0, 1, 0) > DateTime(0, 0, 0)
 def test_less_minute(self):
     assert DateTime(0, 0, 1) > DateTime(0, 0, 0)
 def setUp(self):
   self.stamp = DateTime.check_timestamp("")