Пример #1
0
def champ_from_skins() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    skins: str = censor_name(
        '\n'.join([f'- "{skin.name}"' for skin in champ.skins[1:]]),
        *champ.name.split())

    return Question("Which champion's skins are these?", skins, champ.name)
Пример #2
0
def champ_from_splash() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    # skins[0] is the classic skin
    skin: Skin = random.choice(champ.skins[1:])

    return Question("Which skin is this?", None,
                    skin.name).set_image(url=skin.loading)
Пример #3
0
def spell_from_champ() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    index: int = random.randrange(len(champ.spells))
    spell: Spell = champ.spells[index]

    return Question(f"What's the name of {champ.name}'s {'QWER'[index]}?", None, spell.name).\
        set_thumbnail(url=util.get_image_link(spell.image))
Пример #4
0
def spell_from_desc() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    index: int = random.randrange(len(champ.spells))
    spell: Spell = champ.spells[index]
    desc: str = censor_name(util.SANITIZER.handle(spell.description),
                            champ.name, spell.name)

    return Question("What's the name of this spell?", desc, spell.name, extra=f" ({champ.name} {'QWER'[index]})").\
        set_thumbnail(url=util.get_image_link(spell.image))
Пример #5
0
def get_champion_by_name(name: str) -> Tuple[Optional[Champion], int]:
    """Get a champion by name with fuzzy search.
    Args:
        name: Name of champion 

    Returns:
        Tuple[Optional[Champion], int]: Second element represents the query score (how close it is to the actual value).
    """
    return get_by_name(name, riotapi.get_champions())
Пример #6
0
def champ_from_spell() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    index: int = random.randrange(len(champ.spells))
    spell: Spell = champ.spells[index]

    return Question(f"Which champion has an ability called '{spell.name}'?",
                    None,
                    champ.name,
                    extra=f" ({'QWER'[index]})")
Пример #7
0
def title_from_champ() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())

    def remove_the(text: str) -> str:
        text = text.lower()
        return text[3:].strip() if text.startswith("the") else text

    return Question(f"What is {champ.name}'s title?", None, champ.title, modifier=remove_the).\
        set_thumbnail(url=util.get_image_link(champ.image))
Пример #8
0
def _load_skins() -> Dict[str, SkinInfo]:
    with open("data/skins.json", "r") as f:
        data: Dict[str, Tuple[str, str]] = json.load(f)

    skins: Dict[str, SkinInfo] = {}
    for champ in riotapi.get_champions():
        for skin in champ.skins:
            name = skin.name if skin.name != "default" else f"Classic {champ.name}"
            skins[name] = SkinInfo(champ, skin, *data.get(str(skin.id), (None, None)))

    return skins
Пример #9
0
def main():
    # Setup riotapi
    riotapi.set_region("NA")
    riotapi.print_calls(True)
    os.environ["DEV_KEY"] = "94e831f6-ef9f-4823-81fc-cfc9342f4428"
    key = os.environ["DEV_KEY"]  # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here.
    riotapi.set_api_key(key)
    riotapi.set_load_policy(LoadPolicy.lazy)

    champions = riotapi.get_champions()
    mapping = {champion.name for champion in champions}

    print(mapping)
Пример #10
0
def championstats(champion, role):
    champbuild = ChampionBuilds.query.filter_by(key=champion.capitalize(), role=role).first()
    champgen = ChampionGeneral.query.filter_by(key=champion.capitalize(), role=role).first()

    # If someone enters bad url directly like /champions/noob/top, redirect to champ landing
    if champbuild is None or champgen is None:
        error = "Champion or role for champion not found. Try another."
        champs = sorted(riotapi.get_champions(), key=lambda champion: champion.name)
        roles = ChampionGeneral.query.order_by(ChampionGeneral.key).all()
        return render_template('championlanding.html', error=error, champs=champs, roles=roles)

    # Items
    popularitems = champbuild.popularitems.split(",")
    winningitems = champbuild.winningitems.split(",")
    popstartitems = champbuild.popstartitems.split(",")
    winstartitems = champbuild.winstartitems.split(",")

    # Skills
    popularskills = champbuild.popularskills
    winningskills = champbuild.winningskills
    # Result is a string, which is already iterable letter by letter. No split needed.

    # Masteries
    popularmasteries = [x.split("-") for x in champbuild.popularmasteries.split(",")]
    winningmasteries = [x.split("-") for x in champbuild.winningmasteries.split(",")]
    # Makes list structured like [ [points, masteryid], [points, masteryid], ... ]

    # Runes
    popularrunes = [x.split("-") for x in champbuild.popularrunes.split(",")]
    winningrunes = [x.split("-") for x in champbuild.winningrunes.split(",")]
    # Makes list structured like [ [points, runeid], [points, runeid], ... ]

    poprunes = riotapi.get_runes(ids=[int(i[1]) for i in popularrunes])
    winrunes = riotapi.get_runes(ids=[int(i[1]) for i in winningrunes])

    print(poprunes)



    return render_template('championstats2.html',
                            str=str,
                            champbuild=champbuild,
                            champgen=champgen,
                            champion=champion,
                            len=len,
                            enumerate=enumerate,
                            popularitems=popularitems, winningitems=winningitems, popstartitems=popstartitems, winstartitems=winstartitems,
                            popularskills=popularskills, winningskills=winningskills,
                            popularmasteries=popularmasteries, winningmasteries=winningmasteries,
                            popularrunes=popularrunes, winningrunes=winningrunes, poprunes=poprunes, winrunes=winrunes)
Пример #11
0
    def train(self, general_summoners, streamer_summoners):
        self._champion_indexes = sorted(
            [champion.id for champion in riotapi.get_champions()])

        data = np.zeros((len(general_summoners), len(self._champion_indexes)),
                        dtype=np.float)
        for i, row in enumerate(
                map(
                    lambda x: get_mastery_vector(self._champion_indexes, x[
                        "masteries"]), general_summoners)):
            data[i] = row

        self._projection = manifold.LocallyLinearEmbedding(
            n_components=NUM_COMPONENTS)
        self._projection.fit(data)
        self._update_streamer_tree(streamer_summoners)
def main():
    # Setup riotapi
    riotapi.set_region("NA")
    riotapi.print_calls(True)
    key = os.environ["DEV_KEY"]  # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here.
    riotapi.set_api_key(key)
    riotapi.set_load_policy(LoadPolicy.lazy)

    champions = riotapi.get_champions()
    mapping = {champion.id: champion.name for champion in champions}

    print(mapping)

    print()

    # Annie's champion ID is 1, so this will print "Annie"
    print(mapping[1])
def main():
    # Setup riotapi
    riotapi.set_region("NA")
    riotapi.print_calls(True)
    key = os.environ[
        "DEV_KEY"]  # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here.
    riotapi.set_api_key(key)
    riotapi.set_load_policy(LoadPolicy.lazy)

    champions = riotapi.get_champions()
    mapping = {champion.id: champion.name for champion in champions}

    print(mapping)

    print()

    # Annie's champion ID is 1, so this will print "Annie"
    print(mapping[1])
Пример #14
0
def summoner(sumName):
    # images_names = os.listdir('myapplication/static/images/planes')
    # planeswalkerNames = planeswalker_dict.keys()
    username = riotapi.get_summoner_by_name(sumName)
    # rankedstats = riotapi.get_ranked_stats(sumName)
    champions = riotapi.get_champions()
    # championIds = riotapi.get_champions()
    # mapping = {champion.id: champion.name for champion in championIds}
    #
    # runes = riotapi.get_rune_pages(sumName)
    sumId = username.id
    match1 = riotapi.get_match_list(username, 3)
    championName = riotapi.get_champion_by_name(match1)
    # match = riotapi.get_match(2034758953)
    masteryStats = riotapi.get_champion_mastery_score(username)
    return render_template('testhome.html',
                           summoner=username,
                           champions=champions,
                           match=match1,
                           championName=championName,
                           masteryscore=masteryStats)
Пример #15
0
 def __init__(self):
     riotapi.set_region("NA")
     riotapi.set_api_key("462d0d85-d692-4af5-b91f-4ed9cf0b2efe")
     self.champions = riotapi.get_champions()
     self.items = riotapi.get_items()
Пример #16
0
def action(message, client, config):
    if config.has_option("lolinfo", "time_limit"):
        time_limit = config.getint("lolinfo", "time_limit")
    else:
        time_limit = 60

    if config.has_option("lolinfo", "permitted_channels"):
        permitted_channels = json.loads(config.get('lolinfo', 'permitted_channels'))
    else:
        permitted_channels = []

    if not rl.is_rate_limited(message.author.id, "lolinfo", time_limit) and message.channel.name in permitted_channels:
        api_key = config.get("BotSettings", "lol_api")
        riotapi.set_region("NA")
        riotapi.set_api_key(api_key)

        split_message = message.content.split()

        if split_message[0] == "!lol":
            if len(split_message) > 1:
                if split_message[1] == "last" and len(split_message) > 2:
                    try:
                        summoner_name = ' '.join(split_message[2:])
                        summoner = riotapi.get_summoner_by_name(summoner_name)
                        last_game = summoner.recent_games()[0]

                        champion = last_game.champion.name
                        kda = last_game.stats.kda
                        kda_tuple = (last_game.stats.kills, last_game.stats.deaths, last_game.stats.assists)
                        cs = last_game.stats.minion_kills
                        level = last_game.stats.level
                        win = last_game.stats.win
                        wards = last_game.stats.wards_placed
                        vision_wards = last_game.stats.vision_wards_bought
                        time_played = last_game.stats.time_played/60
                        side = last_game.stats.side.name
                        gold_earned = last_game.stats.gold_earned
                        total_wards = wards + vision_wards

                        role = last_game.stats.role
                        if role is None:
                            role = "IDONTKNOW"
                        else:
                            role = role.name

                        lane = last_game.stats.lane
                        if lane is None:
                            lane = "IDONTKNOW"
                        else:
                            lane = lane.value.lower()

                        if win:
                            victory = "won"
                        else:
                            victory = "lost"

                        message1 = "%s %s their last game as %s playing %s in the %s lane on the %s side in %.1f minutes." % (summoner_name, victory, champion, role, lane, side, time_played)
                        message2 = "They finished the game with a KDA of %.1f and CS of %s. They were level %s and earned %s gold. They placed %s wards." % (kda, cs, level, gold_earned, total_wards)

                        full_message = message1 + " " + message2

                        yield from client.send_message(message.channel, full_message)
                    except APIError as error:
                        if error.error_code in [500]:
                            yield from client.send_message(message.channel, "I had trouble connecting, try again in a little while.")
                        if error.error_code in [404]:
                            yield from client.send_message(message.channel, "I couldn't find that Summoner.")
                    except:
                        print(traceback.format_exc())

                if split_message[1] == "tip":
                    try:
                        tip_type = random.choice(['ally', 'enemy'])
                        random_champ = random.choice(riotapi.get_champions())

                        tip = "I ain't got no tips for you, soz."

                        if tip_type == "ally":
                            tip = random.choice(random_champ.ally_tips)
                        if tip_type == "enemy":
                            tip = random.choice(random_champ.enemy_tips)

                        yield from client.send_message(message.channel, tip)
                    except APIError as error:
                        if error.error_code in [500]:
                            yield from client.send_message(message.channel, "I had trouble connecting, try again in a little while.")
                    except:
                        print(traceback.format_exc())
Пример #17
0
import random

from cassiopeia import riotapi

riotapi.set_region("BR")
riotapi.set_api_key("9bb95c2c-6d74-4b3b-911b-9fda01efc0db")



summoner = riotapi.get_summoner_by_name("Yarquen")
print("{name} is a level {level} summoner on the BR server." . format(name=summoner.name, level=summoner.level))

champions = riotapi.get_champions()
random_champion = random.choice(champions)
print("He enjoys playing LoL on all different champions, like {name}.".format(name=random_champion.name))

challenger_league = riotapi.get_challenger()
best_na = challenger_league[0].summoner
print("He's much better at writing Python code than he is at LoL. He'll never be as good as {name}.".format(name=best_na.name))
Пример #18
0
# http://cassiopeia.readthedocs.io/en/latest/setup.html#setting-additional-environment-variables

summoner = riotapi.get_summoner_by_name("Verciau")
print(
    "{name} is a level {level} summoner on the NA server. He rocks on these champs:"
    .format(name=summoner.name, level=summoner.level))

ranked = summoner.ranked_stats()

print("{name} has played {numChamps} champions this season.".format(
    name=summoner.name, numChamps=len(ranked)))

for entry in ranked.items():
    winRate = entry[1].wins / entry[1].games_played
    if winRate > 0.5:
        print("Champ: {champ} | Wins: {wins} | Games Played: {played}".format(
            champ=entry[0].name,
            wins=entry[1].wins,
            played=entry[1].games_played))

champions = riotapi.get_champions()
random_champion = random.choice(champions)
print("He enjoys playing LoL on all different champions, like {name}.".format(
    name=random_champion.name))

challenger_league = riotapi.get_challenger()
best_na = challenger_league[0].summoner
print(
    "He's much better at writing Python code than he is at LoL. He'll never be as good as {name}."
    .format(name=best_na.name))
Пример #19
0
def test_champions():
    int_test_handler.test_result(riotapi.get_champions())
Пример #20
0
import pandas as pd
import cassiopeia.riotapi as cass

# Set Default Region to "NA", if using functions in ItemBuild for summoners from other region, must reset
defregion="NA"
api_key="e7626459-3d30-430e-ad39-d6cd79428aef"

cass.set_region(defregion)
cass.set_api_key(api_key)
champs = cass.get_champions()

def BuildItemDF():

    items = cass.get_items()
    df = pd.DataFrame(list(map(lambda x: (x.id,x.name),items)),columns=["id","item"])
    return df

def BuildChampDF():

    champs = cass.get_champions()
    df = pd.DataFrame(list(map(lambda x: (x.id,x.name),champs)),columns=["id","name"])
    return df

items = BuildItemDF()
champions = BuildChampDF()
Пример #21
0
def passive_from_champ() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())

    return Question(f"What is the name of {champ.name}'s passive?", None, champ.passive.name).\
        set_thumbnail(url=util.get_image_link(champ.passive.image))
Пример #22
0
from cassiopeia import riotapi
from operator import attrgetter, itemgetter

api_key = "FIND-ME"

riotapi.set_region("EUW")
riotapi.set_api_key(api_key)
me = riotapi.get_summoner_by_name("Sondjaskysa")
order_dict = {
    "total": attrgetter("level", "points"),
    "nearest": attrgetter("points_until_next_level")
}

ALL_CHAMP_NAMES = set([c.name for c in riotapi.get_champions()])


def check_ingame(summoner=me):
    return riotapi.get_current_game(summoner)


def get_full_masteries(name=me.name, order="total"):
    champs = riotapi.get_summoner_by_name(name).champion_masteries()
    order = order_dict[order] or attrgetter("level", "points")
    return sorted(champs.values(), key=order, reverse=True)


def suggest_easy(name=me.name, limit=1300, check_box=True):
    champs = get_full_masteries(name=name, order="nearest")
    max_level = lambda x: x.points_until_next_level == 0
    unskilled_champs = ALL_CHAMP_NAMES.difference(
        [c.champion.name for c in champs])
Пример #23
0
def champ_from_passive() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    desc: str = censor_name(champ.passive.sanitized_description, champ.name)

    return Question("Which champion's passive is this?", desc, champ.name)
Пример #24
0
def BuildChampDF():

    champs = cass.get_champions()
    df = pd.DataFrame(list(map(lambda x: (x.id,x.name),champs)),columns=["id","name"])
    return df
Пример #25
0
def action(message, client, config):
    api_key = config.get("BotSettings", "lol_api")
    riotapi.set_region("NA")
    riotapi.set_api_key(api_key)

    split_message = message.content.split()

    if split_message[0] == "!lol":
        if split_message[1] == "last":
            try:
                summoner_name = ' '.join(split_message[2:])
                summoner = riotapi.get_summoner_by_name(summoner_name)
                last_game = summoner.recent_games()[0]

                champion = last_game.champion.name
                kda = last_game.stats.kda
                kda_tuple = (last_game.stats.kills, last_game.stats.deaths,
                             last_game.stats.assists)
                cs = last_game.stats.minion_kills
                level = last_game.stats.level
                win = last_game.stats.win
                wards = last_game.stats.wards_placed
                vision_wards = last_game.stats.vision_wards_bought
                time_played = last_game.stats.time_played / 60
                side = last_game.stats.side.name
                gold_earned = last_game.stats.gold_earned
                total_wards = wards + vision_wards

                role = last_game.stats.role
                if role is None:
                    role = "IDONTKNOW"
                else:
                    role = role.name

                lane = last_game.stats.lane
                if lane is None:
                    lane = "IDONTKNOW"
                else:
                    lane = lane.value.lower()

                if win:
                    victory = "won"
                else:
                    victory = "lost"

                message1 = "%s %s their last game as %s playing %s in the %s lane on the %s side in %.1f minutes." % (
                    summoner_name, victory, champion, role, lane, side,
                    time_played)
                message2 = "They finished the game with a KDA of %.1f and CS of %s. They were level %s and earned %s gold. They placed %s wards." % (
                    kda, cs, level, gold_earned, total_wards)

                full_message = message1 + " " + message2

                yield from client.send_message(message.channel, full_message)
            except APIError as error:
                if error.error_code in [500]:
                    yield from client.send_message(
                        message.channel,
                        "I had trouble connecting, try again in a little while."
                    )
                if error.error_code in [404]:
                    yield from client.send_message(
                        message.channel, "I couldn't find that Summoner.")
            except:
                print(traceback.format_exc())

        if split_message[1] == "tip":
            try:
                tip_type = random.choice(['ally', 'enemy'])
                random_champ = random.choice(riotapi.get_champions())

                tip = "I ain't got no tips for you, soz."

                if tip_type == "ally":
                    tip = random.choice(random_champ.ally_tips)
                if tip_type == "enemy":
                    tip = random.choice(random_champ.enemy_tips)

                yield from client.send_message(message.channel, tip)
            except APIError as error:
                if error.error_code in [500]:
                    yield from client.send_message(
                        message.channel,
                        "I had trouble connecting, try again in a little while."
                    )
            except:
                print(traceback.format_exc())
Пример #26
0
def champ_from_lore() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())
    lore: str = censor_name(util.SANITIZER.handle(champ.blurb), champ.name)

    return Question("Which champion's lore is this?", lore, champ.name)
Пример #27
0
def champ_from_title() -> Question:
    champ: Champion = random.choice(riotapi.get_champions())

    return Question(f"Which champion is '{champ.title}'?", None, champ.name)
Пример #28
0
	def ready(self):
		riotapi.set_region("NA")
		riotapi.set_api_key("APIKEY")
		riotapi.get_champions()
		print("got champs")
Пример #29
0
def champions():
    champs = sorted(riotapi.get_champions(), key=lambda champion: champion.name)
    roles = ChampionGeneral.query.order_by(ChampionGeneral.key).all()
    return render_template('championlanding.html',
                            champs = champs,
                            roles = roles)
    def _init_champions(all_champions=None):
        if not all_champions:
            all_champions = riotapi.get_champions()
            Build._champions_by_id = {champion.id: Champion(champion) for champion in all_champions}

        Build._champions_by_name = {champion.name: champion for _, champion in Build._champions_by_id.items()}
Пример #31
0
def test_champions():
    int_test_handler.test_result(riotapi.get_champions())