Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#Made by Andris Jansons
import json
import urllib.request
import pickle
def leagueCounterTipsSet():
"""Makes a file with a dictionary of champion information"""
with urllib.request.urlopen('https://eun1.api.riotgames.com/lol/static-data/v3/champions?locale=en_US&tags=enemytips&dataById=false&api_key=RGAPI-536028dc-df04-4f01-b2c3-5b7612ce940b') as response:
rawdata = response.read()
jsondata = json.loads(rawdata)
counterTips = jsondata['data']
with open('leagueData.txt','wb') as f:
pickle.dump(jsondata['data'], f) # load dictionary in a file
f.close()
def leagueCounterTips(champion):
"""Return counter tips for a specific league champion"""
champion = champion[0].upper() + champion[1:] # Make the first letter uppercase
try:
with open('leagueData.txt', 'rb') as f:
dataDict = pickle.load(f)
f.close()
counterTips = ''
for tip in dataDict[champion]['enemytips']:
counterTips = counterTips + tip + "\n"
return counterTips[:-1]
except KeyError: # If champion is not found
return "There is no champion with that name."
except: # If the file does not exist. because Riot let's us call the api 10 times/hour
leagueCounterTipsSet()
with open('leagueData.txt', 'rb') as f:
dataDict = pickle.load(f)
f.close()
counterTips = ''
for tip in dataDict[champion]['enemytips']:
counterTips = counterTips + tip + "\n"
return counterTips[:-1] # Also remove the new line at the end