-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChampionMasteryProgram.py
More file actions
236 lines (176 loc) · 6.78 KB
/
Copy pathChampionMasteryProgram.py
File metadata and controls
236 lines (176 loc) · 6.78 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# LoL Champion Mastery Retrieval Program (User Interface)
# 2/15/17
import riot_api
import outputs
import text_writer
import urllib.error
import json.decoder
import time
import sys
REGION = 'NA'
CHAMPION_JSON_DATA = outputs.ChampionList()
# *****************************
# Trivial Functions
# *****************************
def loading() -> None:
'''
Displays loading to make sure program is not frozen.
'''
for char in '.....':
print(char, end='')
time.sleep(0.5)
sys.stdout.flush()
return
# *****************************
# User Interface Functions
# *****************************
def enter_summoner_name() -> str:
'''
Prompts user to enter summoner name.
'''
summoner_name = input('Summoner name: ').lower()
for char in summoner_name:
if char in '!@#$%^&*()-<>?;:\'"[]{}+=~`':
print('Invalid summoner name.')
print('Please restart.')
return summoner_name
def get_summoner_name(summonerID: str) -> str:
'''
Returns summoner name using summoner ID.
'''
summoner_name = outputs.SummonerName(summonerID).get_output()
return summoner_name
def get_summonerID(summoner_name: str) -> str:
'''
Returns summoner ID using summoner name.
'''
summonerID = outputs.SummonerID(summoner_name).get_output()
return summonerID
def get_current_game_dict(summoner_name: str) -> dict and list:
'''
Returns a dict of summoner IDs (key) and champion IDs (value) and list of summoner names.
'''
global REGION
final_dict = dict()
summonerID = get_summonerID(summoner_name)
current_game_json = outputs.CurrentGame(REGION, summonerID).get_output()
summoner_list = current_game_json['participants']
summoner_names_list = list()
summoner_ids_list = list()
for summoner in summoner_list:
final_dict[str(summoner['summonerId'])] = str(summoner['championId'])
summoner_names_list.append(summoner['summonerName'])
summoner_ids_list.append(str(summoner['summonerId']))
return final_dict, summoner_names_list, summoner_ids_list
def get_champion(championID: str) -> str:
'''
Returns champion name from champion ID.
'''
global CHAMPION_JSON_DATA
champion_name = CHAMPION_JSON_DATA.get_output(championID)
return champion_name + '\n'
def get_champion_mastery(summonerID: str, championID: str) -> str:
'''
Returns champion mastery output.
'''
global REGION
champ_mastery = outputs.ChampionMastery(REGION, summonerID, championID).get_output()
return champ_mastery
def get_summoner_ranks(summonerID_list: 'list of summoner IDs') -> dict:
'''
Returns dictionary of summoner
'''
summoner_ranks = outputs.SummonerRanks(summonerID_list).get_output()
return summoner_ranks
def check_for_unranked(summonerID: str, summoner_ranks: dict) -> str:
'''
Returns rank of summoner based on summoner name and summoner ranks dictionary.
'''
if summonerID in summoner_ranks:
return 'Rank (SoloQ 5v5): ' + summoner_ranks[summonerID]
else:
return 'Rank (SoloQ 5v5): (͡°͜ʖ͡°) UNRANKED (͡°͜ʖ͡°)\n'
def generate_outputs(print_dict: dict) -> None:
'''
Prints a string as a final output.
'''
print('**********************************')
for item in print_dict:
print()
print('Summoner: ' + item)
print(print_dict[item])
return
def user_interface() -> None:
try:
summoner_name = enter_summoner_name()
start_time = time.time() # Starts timer for total execution time
print('Loading', end='')
summoners_and_champs, summoner_names_list, summoner_ids_list = get_current_game_dict(summoner_name)
dict_to_print = dict()
count = 0
summoner_ranks = get_summoner_ranks(summoner_ids_list)
for summoner in summoners_and_champs:
## print('Loading ' + summoner, end='')
## loading()
print('.', end='')
sys.stdout.flush()
dict_to_print[summoner_names_list[count]] = get_champion(summoners_and_champs[summoner]) + \
check_for_unranked(summoner, summoner_ranks) + \
get_champion_mastery(summoner, summoners_and_champs[summoner])
count += 1
print('\n')
generate_outputs(dict_to_print)
except urllib.error.HTTPError as e:
print()
print('**********************************')
print('Failed to retrieve from Riot API.')
print('Status code: {}'.format(e.code))
## if e.code == 404:
## print(summoner_name + ' is not in a game.')
print('**********************************')
except json.decoder.JSONDecodeError:
print()
print('**********************************')
print('Failed to load some JSON data from Riot API.')
print('Sorry for the inconvenience.')
print('**********************************')
try:
print()
print('**********************************')
print('Total execution time:')
print('--- %s seconds ---' % (time.time() - start_time))
print('**********************************')
print()
print('**********************************')
print('Champion Mastery Retrieval Program v0.1')
print('Produced and Created by JahnC')
print('**********************************')
print()
input('Enter to exit program.')
except UnboundLocalError:
print()
print('**********************************')
print('Execution Failure.')
print('**********************************')
print()
print('**********************************')
print('Champion Mastery Retrieval Program v0.1')
print('Produced and Created by JahnC')
print('**********************************')
print()
input('Enter to exit program.')
except NameError:
print()
print('**********************************')
print('Execution Failure.')
print('**********************************')
print()
print('**********************************')
print('Champion Mastery Retrieval Program v0.1')
print('Produced and Created by JahnC')
print('**********************************')
print()
input('Enter to exit program.')
return
if __name__ == '__main__':
user_interface()