This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConfigUpdater.py
executable file
·115 lines (105 loc) · 6.16 KB
/
ConfigUpdater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!python
# Update the working patch and champions list
from __future__ import print_function
import configparser
import json
import os
import urllib.request
from datetime import datetime
from slugify import slugify
from collections import OrderedDict
from InterfaceAPI import InterfaceAPI
def run():
config = configparser.ConfigParser()
if os.path.isfile('config.ini'):
config.read('config.ini')
API_KEY = config['PARAMS']['api-key']
else:
def validationInput(msg, validAns):
while True:
ans = input(msg)
if ans.lower() in validAns:
return ans
print('Incorrect value. Only', validAns, 'are accepted')
config.add_section('PARAMS')
config.add_section('LEAGUES')
config.add_section('REGIONS')
config.add_section('PATCHES')
config.add_section('CHAMPIONS')
config.add_section('ROLES')
config.add_section('TOP')
config.add_section('JUNGLE')
config.add_section('MID')
config.add_section('CARRY')
config.add_section('SUPPORT')
print("No config file found. Let's set up a few parameters (you may change them anytime by manually editing config.ini).")
API_KEY = input('- API-KEY (https://developer.riotgames.com/): ')
config['PARAMS']['api-key'] = API_KEY
config['PARAMS']['database'] = input('- Database location (eg. C:\LoLAnalyzerDB): ')
if not os.path.isdir(config['PARAMS']['database']):
os.makedirs(config['PARAMS']['database'])
print('Leagues you want to download games from (y/n): ')
print('challenger and grandmaster league enabled by default')
config['LEAGUES']['challenger'] = 'yes'
config['LEAGUES']['grandmaster'] = 'yes'
config['LEAGUES']['master'] = 'yes' if validationInput('- master: ', ['y', 'n']) == 'y' else 'no'
if config['LEAGUES']['master'] == 'yes' :
print('Lower leagues are not recommended unless you have a high rate API-KEY (not given by default)')
config['LEAGUES']['diamond'] = 'yes' if validationInput('- diamond: ', ['y', 'n']) == 'y' else 'no'
if config['LEAGUES']['diamond'] == 'yes' :
config['LEAGUES']['platinum'] = 'yes' if validationInput('- platinum: ', ['y', 'n']) == 'y' else 'no'
if config['LEAGUES']['platinum'] == 'yes' :
config['LEAGUES']['gold'] = 'yes' if validationInput('- gold: ', ['y', 'n']) == 'y' else 'no'
if config['LEAGUES']['gold'] == 'yes' :
config['LEAGUES']['silver'] = 'yes' if validationInput('- silver: ', ['y', 'n']) == 'y' else 'no'
if config['LEAGUES']['silver'] == 'yes' :
config['LEAGUES']['bronze'] = 'yes' if validationInput('- bronze: ', ['y', 'n']) == 'y' else 'no'
print('Regions you want to download games from (y/n):')
print('API-KEY limitations are server-bounded, so you will download way more games enabling everything')
config['REGIONS']['ru'] = 'yes' if validationInput('- ru: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['kr'] = 'yes' if validationInput('- kr: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['br1'] = 'yes' if validationInput('- br1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['oc1'] = 'yes' if validationInput('- oc1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['jp1'] = 'yes' if validationInput('- jp1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['na1'] = 'yes' if validationInput('- na1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['eun1'] = 'yes' if validationInput('- eun1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['euw1'] = 'yes' if validationInput('- euw1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['tr1'] = 'yes' if validationInput('- tr1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['la1'] = 'yes' if validationInput('- la1: ', ['y', 'n']) == 'y' else 'no'
config['REGIONS']['la2'] = 'yes' if validationInput('- la2: ', ['y', 'n']) == 'y' else 'no'
# Update to current patch & champions list
# euw1 is used as reference
api = InterfaceAPI(API_KEY)
PATCHES = api.getData('https://ddragon.leagueoflegends.com/api/versions.json')
PATCHES = ['.'.join(s.split('.')[:2]) for s in reversed(PATCHES)]
config['PARAMS']['download_patches'] = PATCHES[-1]
print('Current patch set to:', config['PARAMS']['download_patches'])
PATCHES = OrderedDict((x, True) for x in PATCHES).keys()
config['PARAMS']['patches'] = ','.join(PATCHES)
print('Patch list updated')
json_data = api.getData('http://ddragon.leagueoflegends.com/cdn/9.7.1/data/en_US/champion.json', data={'locale': 'en_US', 'dataById': 'true'})
CHAMPIONS = json_data['data']
sortedChamps = []
for _, champ_info in CHAMPIONS.items():
slugname = slugify(champ_info['name'], separator='')
config['CHAMPIONS'][slugname] = champ_info['key']
sortedChamps.append(slugname)
# We need to sort champions by release for the neural network
# This is really important for the compatibility of the system over the patches
# Unfortunately the API doesn't give this information, so we use: http://universe-meeps.leagueoflegends.com/v1/en_us/champion-browse/index.json
response = urllib.request.urlopen('http://universe-meeps.leagueoflegends.com/v1/en_us/champion-browse/index.json')
data = json.loads(response.read().decode())
champ_date = {}
for champ in data['champions']:
date = champ['release-date']
date = date[1:] if date[0] == ' ' else date # solve a problem on annie
date = date[:10] # solve a problem on aatrox
champ_date[slugify(champ['name'], separator='')] = datetime.strptime(date, '%Y-%m-%d')
sortedChamps.sort(key=lambda x: (champ_date[x], x)) # sorted by date and then abc order (eg. annie/yi or xhaya/rakan)
config['PARAMS']['sortedChamps'] = ','.join(sortedChamps)
print('Champions list updated')
with open('config.ini', 'w') as configfile:
config.write(configfile)
print('-- Update complete --')
if __name__ == '__main__':
run()