Add skills order and use champ id for folder

This commit is contained in:
nyyu 2018-06-02 19:38:00 +02:00
parent 47c9898c5c
commit d0869d2f1d

View file

@ -12,7 +12,7 @@ LOL_CHAMPS_DIR = r'C:\\League of Legends\\Config\\Champions\\'
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0'}
def getChampData(champ, position):
page = requests.get('http://champion.gg/champion/%s/%s' % (champ, position), headers=HEADERS).text
page = requests.get('http://champion.gg/champion/%s/%s?league=' % (champ, position), headers=HEADERS).text
return json.loads(PATTERN_CHAMPIONGG.search(page).group(1))
def getChampsWithPositionsAndPatch():
@ -34,24 +34,23 @@ def makeItemSet(data, label):
"type": "%s (%.2f %% - %d games)" % (label, data['winPercent'] * 100, data['games'])
}
def makeItemSetFromList(list, label):
def makeItemSetFromList(list, label, key, data):
return {
"items": [{ "id": str(id), "count": 1} for id in list],
"type": "%s" % (label)
"type": label % '.'.join([data['skills']['skillInfo'][int(k)-1]['key'] for k in data['skills'][key]['order']])
}
def writeItemSet(id, pos, ver, data, path):
logging.info('Writing item set for %s at %s' % (id, pos))
item_set = {
"map": "any",
"blocks": [],
"title": "CGG %s %s" % (pos, ver),
"priority": False,
"mode": "any",
"type": "custom",
"sortrank": 1,
"champion": "%s" % id
"map": "any",
"mode": "any",
"priority": False,
"sortrank": 0,
"blocks": []
}
if 'mostGames' in data['firstItems']:
@ -62,9 +61,9 @@ def writeItemSet(id, pos, ver, data, path):
item_set['blocks'].append(makeItemSet(data['items']['mostGames'], 'Most Frequent Core Build'))
if 'highestWinPercent' in data['items']:
item_set['blocks'].append(makeItemSet(data['items']['highestWinPercent'], 'Highest Win % Core Build'))
item_set['blocks'].append(makeItemSetFromList([2003, 2004, 2055, 2031, 2032, 2033, 2138, 2140, 2139], "Consumables"))
item_set['blocks'].append(makeItemSetFromList([3340, 3364, 3363], "Trinkets"))
item_set['blocks'].append(makeItemSetFromList([2003, 2004, 2055, 2031, 2032, 2033, 2138, 2140, 2139], "Consumables | Frequent: %s", 'mostGames', data))
item_set['blocks'].append(makeItemSetFromList([3340, 3364, 3363], "Trinkets | Wins: %s", 'highestWinPercent', data))
with open('%sCGG_%s_%s.json' % (path, id, pos), 'w', newline='\n') as out:
json.dump(item_set, out, indent=4)
@ -90,7 +89,7 @@ def main():
for name, positions in champ.items():
c = next((x for x in lol_champs if x['name'] == name), None)
if c is not None:
path = '%s%s\\Recommended\\' % (LOL_CHAMPS_DIR, name)
path = '%s%s\\Recommended\\' % (LOL_CHAMPS_DIR, c['id'])
Path(path).mkdir(parents=True, exist_ok=True)
for pos in positions:
writeItemSet(c['id'], pos, patch, getChampData(c['id'], pos), path)