def get_items(): items = cass.get_items(region="NA") for item in items: print(item.name) items = cass.get_items(region="NA") print(items[10].name) dagger = Item(name="Dagger", region="NA") print(dagger.name, dagger.id) items = Items(region="NA") print(items[10].name)
def test_items(): dagger = Item(name="Dagger", region="NA") dagger.name dagger.id items = cass.get_items(region="NA") for item in items: item.name items = cass.get_items(region="NA") items[10].name dagger = Item(name="Dagger", region="NA") dagger.name, dagger.id items = Items(region="NA") items[10].name
def test_items(): dagger = Item(name="Dagger", region="NA") dagger.name dagger.id items = cass.get_items(region="NA") for item in items: item.name items = cass.get_items(region="NA") items[10].name dagger = Item(name="Dagger", region="NA") dagger.name, dagger.id items = Items(region="NA") items[10].name
def collectItemUsage(): matchesList = collectMatches() # Start by creating dictionaries of every spell, item, rune, and champion names try: itemUsage = { champion.name: [{ spell.name: 0 for spell in kass.get_summoner_spells(region="NA") }, {item.name: 0 for item in kass.get_items(region="NA")}, {rune.name: 0 for rune in kass.get_runes(region="NA")}] for champion in kass.get_champions(region="NA") } except Warning as err: print(err) for match in matchesList: for player in match.participants: currWin = player.stats.win if (currWin): # Only care if there was a win for the champion currChamp = player.champion.name if player.summoner_spell_d.name in itemUsage[currChamp][0]: itemUsage[currChamp][0][player.summoner_spell_d.name] += 1 if player.summoner_spell_f.name in itemUsage[currChamp][0]: itemUsage[currChamp][0][player.summoner_spell_f.name] += 1 for item in player.stats.items: if item is not None and item.name in itemUsage[currChamp][ 1]: itemUsage[currChamp][1][item.name] += 1 for rune in player.runes: if rune is not None and rune.name in itemUsage[currChamp][ 2]: itemUsage[currChamp][2][rune.name] += 1 return itemUsage
def _init_items(all_items=None): if not all_items: all_items = cass.get_items() ItemSet._items_by_id = {item.id: Item(item) for item in all_items if Map.summoners_rift in item.maps} else: ItemSet._items_by_id = all_items ItemSet._items_by_name = {item.name: item for _, item in ItemSet._items_by_id.items()}
def update_items(): from . import consts as Consts from .models import Items import cassiopeia as cass items = cass.get_items(region='NA') for item in items: if item.id in ornnable or item.gold.total > 1200 and item.builds_into == []: Items.objects.get_or_create(item_id=item.id, item_type=Consts.ITEM_CORE) for boot in boots: Items.objects.get_or_create(item_id=boot, item_type=Consts.ITEM_BOOTS)
def get_item(name_or_id: Union[str, int]) -> Tuple[Optional[Item], int]: """Get an item by name with fuzzy search. Args: name_or_id: Name or id of item Returns: Tuple[Optional[Item], int]: Second element represents the query score (how close it is to the actual value). """ items = riotapi.get_items() try: item = items[int(name_or_id)] return item, 100 if item else 0 except (TypeError, KeyError, ValueError): return get_by_name(name_or_id, items)
def load_all(self, refresh: bool = False): # Save refresh variable so we don't have to pass it into every method self.refresh = refresh if refresh: cassiopeia.configuration.settings.clear_sinks() cassiopeia.configuration.settings.expire_sinks() # Open the download popup, start downloading data and updating the # progress bar as we go progress_popup = hinter.ui.progress.Progress( 0, 'Downloading and processing: Champions') cassiopeia.get_champions() progress_popup.update(70, 'Downloading and processing: Items') cassiopeia.get_items() progress_popup.update(80, 'Downloading and processing: Maps') cassiopeia.get_maps() progress_popup.update(81, 'Downloading and processing: Spells') cassiopeia.get_summoner_spells() progress_popup.update(82, 'Downloading and processing: Runes') cassiopeia.get_runes() progress_popup.update(85, 'Downloading and processing: Rank icons') self.load_rank_icons(refresh) # Inform user data refresh completed, wait, then close the popup progress_popup.update(100, 'Data refresh complete! Window will close') time.sleep(3) progress_popup.close() # Do not update again until this is called, refresh data loaded checks self.refresh = False
ALLOWED_MODES: Set[str] = { mode.upper() for mode in config["trivia"]["allowed_modes"] } ALLOWED_SPELLS: List[SummonerSpell] = \ [spell for spell in riotapi.get_summoner_spells() if not ALLOWED_MODES.isdisjoint(util.find_in_data(spell, "modes"))] # ALLOWED_MAPS: Set[str] = \ # {str(Map[map.lower()].value) if not map.isdigit() else map for map in config["trivia"]["allowed_maps"]} ALLOWED_MAPS: Set[int] = \ {int(riotapi.get_maps()[map].id) if not map.isdigit() else int(map) for map in config["trivia"]["allowed_maps"]} print(ALLOWED_MAPS) ALLOWED_ITEMS: List[Item] = [] for item in riotapi.get_items(): # print(list(map.id for map in item.maps)) if not ALLOWED_MAPS.isdisjoint(int(map.id) for map in item.maps): ALLOWED_ITEMS.append(item) PERCENT_STATS: List[str] = [ "percent", "spell_vamp", "life_steal", "tenacity", "critical", "attack_speed", "cooldown" ] class Question(object): """A trivia question """ def __init__(self, title: str,
# reading match list import json # importing functions from etl_functions import id_match path = 'D:/Python/lol_dashboard' with open(path + '/data/loaded_matches.json') as f: match_list = json.load(f) # setting api key key = 'RGAPI-83d9b69d-993f-48df-8bf6-0573100e4db0' cass.set_riot_api_key(key) # pulling items, and champion data items = cass.get_items(region='NA') items = list(items) champs = cass.get_champions(region='NA') champs = list(champs) # filling out the match, summoner, match instance, champion selection # this essentially populates all intersecting entities match_ids = [] match_ids_intersect = [] duration = [] creation = [] summoner_ids = [] champ_ids_intersect = [] summoner_stats = []
def storeMatches(): try: conn = pymysql.connect(user=config.dbUsername, password=config.dbPassword, host=config.dbIP, database=config.dbName) cursor = conn.cursor() except pymysql.Error as err: print(err) # Dict of tables TABLES = {} TABLES['champions'] = ''' CREATE TABLE champions ( champID int NOT NULL, champName varchar(25) NOT NULL, item1 varchar(50), item2 varchar(50), item3 varchar(50), item4 varchar(50), item5 varchar(50), item6 varchar(50), item7 varchar(50), rune1 varchar(35), rune2 varchar(35), rune3 varchar(35), rune4 varchar(35), rune5 varchar(35), rune6 varchar(35), rune7 varchar(35), spell1 varchar(40), spell2 varchar(40), PRIMARY KEY(champName) )''' TABLES['items'] = ''' CREATE TABLE items ( itemID int NOT NULL, itemName varchar(50) NOT NULL, PRIMARY KEY(itemName) )''' TABLES['runes'] = ''' CREATE TABLE runes ( runeID int NOT NULL, runeName varchar(35) NOT NULL, PRIMARY KEY(runeName) )''' TABLES['spells'] = ''' CREATE TABLE spells ( spellID int NOT NULL, spellName varchar(40) NOT NULL, PRIMARY KEY(spellName) )''' # Create the tables from the dict of tables above for name, ddl in TABLES.items(): try: print("Creating table {}: ".format(name), end='') cursor.execute(ddl) conn.commit() except pymysql.Error as err: print(err) else: print("OK") # Fill tables with all champions, items, spells, and runes allChamps = {champion.id: champion.name for champion in kass.get_champions(region="NA")} allItems = {item.id: item.name for item in kass.get_items(region="NA")} allRunes = {rune.id: rune.name for rune in kass.get_runes(region="NA")} allSpells = {spell.id: spell.name for spell in kass.get_summoner_spells(region="NA")} addChamp = ('''INSERT INTO champions (champID, champName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE champName=champName''') addItem = ('''INSERT INTO items (itemID, itemName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE itemName=itemName''') addRune = ('''INSERT INTO runes (runeID, runeName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE runeName=runeName''') addSpell = ('''INSERT INTO spells (spellID, spellName) VALUES (%s, %s) ON DUPLICATE KEY UPDATE spellName=spellName''') try: for champ, name in allChamps.items(): dataChamp = (champ, name) cursor.execute(addChamp, dataChamp) conn.commit() for item, name in allItems.items(): dataItem = (item, name) cursor.execute(addItem, dataItem) conn.commit() for rune, name in allRunes.items(): dataRune = (rune, name) cursor.execute(addRune, dataRune) conn.commit() for spell, name in allSpells.items(): dataSpell = (spell, name) cursor.execute(addSpell, dataSpell) conn.commit() except pymysql.Error as err: print(err) else: print("Tables populated with default data") if conn.open: conn.close() cursor.close()
def get_items(): items = cass.get_items() for item in items: print(item.name) items = cass.get_items() print(items[10].name)
def get_items(): items = cass.get_items(region="NA") for item in items: print(item.name) items = cass.get_items(region="NA") print(items[10].name)
def get_static_data(request, region): region = normalize_region(region) response = {} try: response['version'] = cass.get_version(region=region) items_response = {} items = cass.get_items(region=region) for item in items: item_response = {} item_response['name'] = item.name item_response['totalGold'] = item.gold.total item_response['sellGold'] = item.gold.sell item_response['description'] = item.description item_response['plaintext'] = item.plaintext item_response['from'] = [it.id for it in item.builds_from] items_response[str(item.id)] = item_response runes_response = {} runes = cass.get_runes(region=region) for rune in runes: rune_response = {} rune_response['name'] = rune.name rune_response['path'] = rune.path.name rune_response['shortDescription'] = rune._data[cass.core.staticdata.rune.RuneData].shortDescription #rune.short_description rune_response['isKeystone'] = rune.is_keystone runes_response[str(rune.id)] = rune_response skills_response = {} champion_response = {} champions = cass.get_champions(region=region) for champion in champions: ch = {} ch['name'] = champion.name ch['title'] = champion.title ch['img'] = champion.image.full champion_response[str(champion.id)] = ch skills = ['q', 'w', 'e', 'r'] skill_response = { 'p': {}, 'q': {}, 'w': {}, 'e': {}, 'r': {} } skill_response['p']['img'] = champion.passive.image_info.full skill_response['p']['name'] = champion.passive.name skill_response['p']['description'] = champion.passive.sanitized_description for i, skill in enumerate(skills): skill_response[skill]['img'] = champion.spells[i].image_info.full skill_response[skill]['name'] = champion.spells[i].name skill_response[skill]['description'] = champion.spells[i].sanitized_description skill_response[skill]['cooldowns'] = champion.spells[i].cooldowns skill_response[skill]['costs'] = champion.spells[i].costs skills_response[str(champion.id)] = skill_response response['items'] = items_response response['runes'] = runes_response response['championSkills'] = skills_response response['champions'] = champion_response except Exception as e: log.warn("failed to get static data", e, stack_info=True) return HttpResponse(status=500) return JsonResponse(response)