def test_lck_finals_game_3():
    mh_url = (
        "https://matchhistory.na.leagueoflegends.com/en/#match-details/ESPORTSTMNT03/1353193?gameHash=63e4e6e5d695f410"
    )

    game = lol_esports_parser.get_riot_game(mh_url,
                                            get_timeline=True,
                                            add_names=True)

    with open(os.path.join("json_examples", "lck_game.json"), "w+") as file:
        json.dump(game, file, indent=4)

    assert game["duration"] == 1776
    assert game["teams"]["BLUE"]["players"].__len__() == 5

    faker = next(p for p in game["teams"]["RED"]["players"]
                 if p["inGameName"] == "T1 Faker")

    assert faker["championName"] == "Azir"
    assert faker["endOfGameStats"]["kills"] == 3
    assert faker["endOfGameStats"]["cs"] == 242
    assert faker["runes"][0]["name"] == "Lethal Tempo"

    cuzz = next(p for p in game["teams"]["RED"]["players"]
                if p["inGameName"] == "T1 Cuzz")

    assert "Skirmisher's Sabre - Runic Echoes" in [
        item["name"] for item in cuzz["endOfGameStats"]["items"]
    ]
Beispiel #2
0
 def update_wikitext(self, wikitext, overview_page):
     for template in wikitext.filter_templates():
         if not template.name.matches('MatchSchedule/Game'):
             continue
         if not tl_has(template, 'mh'):
             continue
         if tl_has(template, 'blue') and tl_has(template, 'red') and tl_has(
                 template, 'winner'):
             continue
         if 'gameHash' not in template.get('mh').value.strip():
             continue
         mh_url = (template.get('mh').value.strip())
         # print(mh_url)
         game = lol_esports_parser.get_riot_game(mh_url, add_names=False)
         blue = game["teams"]["BLUE"]['name']
         red = game["teams"]["RED"]['name']
         blue_team = self.site.cache.get_team_from_event_tricode(
             overview_page, blue)
         red_team = self.site.cache.get_team_from_event_tricode(
             overview_page, red)
         if blue_team is not None and red_team is not None:
             template.add('blue', blue_team)
             template.add('red', red_team)
             if game["winner"] == "BLUE":
                 template.add('winner', "1")
             elif game["winner"] == "RED":
                 template.add('winner', "2")
 def update_wikitext(self, wikitext, overview_page: str):
     for template in wikitext.filter_templates():
         if not template.name.matches('MatchSchedule/Game'):
             continue
         if not tl_has(template, 'mh'):
             continue
         if tl_has(template, 'blue') and tl_has(template, 'red') and tl_has(template, 'winner'):
             continue
         if 'gameHash' not in template.get('mh').value.strip():
             continue
         mh_url = (
             template.get('mh').value.strip()
         )
         # print(overview_page)
         # print(mh_url)
         try:
             game = lol_esports_parser.get_riot_game(mh_url)
         except Exception as e:
             self.site.log_error_script(overview_page, e)
             continue
         blue = getattr(game.teams.BLUE.sources, 'inferred_name', None)
         red = getattr(game.teams.RED.sources, 'inferred_name', None)
         blue_team = self.site.cache.get_team_from_event_tricode(overview_page, blue)
         red_team = self.site.cache.get_team_from_event_tricode(overview_page, red)
         if blue_team is not None and red_team is not None:
             template.add('blue', blue_team)
             template.add('red', red_team)
             if game.winner == "BLUE":
                 template.add('winner', "1")
             elif game.winner == "RED":
                 template.add('winner', "2")
    def update_template(self, template: Template):
        # i just added more and more checks to avoid crashing on LPL games over time
        if any(
            [_ in self.current_page.name for _ in ['LPL', 'LDL', 'Demacia']]):
            return
        for param in template.params:
            if '|primary=' in str(param.value):
                return
        if not template.has('statslink'):
            return
        mh = template.get('statslink').value.strip()
        if 'lpl.qq' in mh:
            return
        if 'wanplus' in mh:
            return
        if not mh:
            return
        # sigh ok hopefully we actually have a valid mh now
        print(f'Parsing mh {mh} on page {self.current_page.name}')
        try:
            result = get_riot_game(mh, add_names=True)
        except HTTPError:
            sleep(10)
            result = get_riot_game(mh, add_names=True)
        for param in template.params:
            param: Parameter
            if param.name.startswith('blue') or param.name.startswith('red'):
                # hax, sorry
                team = 'BLUE' if param.name.startswith('blue') else 'RED'
                player = int(param.name[-1]) - 1

                w = param.value
                for tl in w.filter_templates():
                    tl: Template
                    if not tl.name.matches('Scoreboard/Player'):
                        continue
                    primary = result['teams'][team]['players'][player][
                        'primaryRuneTreeName']
                    tl.add('primary', primary, before='secondary')
def test_prime_league_summer():
    # This is a live server game
    mh_url = "https://matchhistory.euw.leagueoflegends.com/en/#match-details/EUW1/4676184349/31980018?tab=overview"

    game = lol_esports_parser.get_riot_game(mh_url,
                                            get_timeline=True,
                                            add_names=True)

    assert game["winner"] == "BLUE"

    series = lol_esports_parser.get_riot_series([mh_url],
                                                get_timeline=True,
                                                add_names=True)

    assert series