Permalink
Cannot retrieve contributors at this time
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?
GroupD3/RiotAPI.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (35 sloc)
1.61 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |