def summoner(request, summoner, region): lol = LeagueOfLegends("1201f800-aced-4abb-9083-714dcf58a36e") lol.set_api_region(region) request.session["region"] = region context = {} try: lol.set_summoner(summoner) data = lol.get_summoner_leagues_entry() print data for key, queue in data.items(): if key in QUEUES: ckey = QUEUES[key] context[ckey] = {} context[ckey]["tier"] = data[key]["tier"] context[ckey]["name"] = data[key]["name"].encode("ascii", "replace") entry = data[key]["entries"][0] context[ckey]["division"] = entry["division"] context[ckey]["division_n"] = DIVISIONS[entry["division"]] context[ckey]["wins"] = entry["wins"] context[ckey]["lp"] = entry["leaguePoints"] context[ckey]["ident"] = entry["playerOrTeamName"] return render(request, "summoner.html", context) # return HttpResponse(json.dumps(data, indent=4), content_type='application/json') except RiotError: raise Http404
class LOLClean(): __default_region = 'br' def __init__(self, key, region=__default_region): self.__api = LeagueOfLegends(key) self.__default_region = region def prepare(self, summoner, region): self.__api.set_api_region(region) self.__api.set_summoner(summoner) # list of strings containing all rank data def rank(self, summoner, region=__default_region): try: self.prepare(summoner, region) data = self.__api.get_summoner_leagues_entry() queues = {} for key, queue in data.items(): entry = queue['entries'][0] queues[key] = { 'tier': queue['tier'], 'name': queue['name'], 'division': entry['division'], 'wins': entry['wins'], 'lp': entry['leaguePoints'], 'ident': entry['playerOrTeamName'].encode('ascii', 'replace'), } queues_output = [] for key, queue in queues.items(): queues_output.append('{0} [{1}] => tier {2} {3} ({4}) # {5} wins # {6} league points'.format(queue['ident'], QUEUES[key], queue['tier'], queue['division'], queue['name'], queue['wins'], queue['lp'])) return (True, queues_output) except RiotError, e: return (False, e.error_msg)
from leagueoflegends import LeagueOfLegends, RiotError lol = LeagueOfLegends('RGAPIfcf985395c46447e815d77ae80c424be') # Call the API with explicit summoner ID id = lol.get_summoner_by_name('thispassing') lol.get_games(id)
##pip install leagueoflegends a = 2 if a==1: from leagueoflegends import LeagueOfLegends, RiotError lol = LeagueOfLegends('587a0251-12ba-4600-86f1-0bc65b21cb57') ##587a0251-12ba-4600-86f1-0bc65b21cb57 ##8e702b3f-50a7-437a-b825-18627375da3e # Call the API with explicit summoner ID id = lol.get_summoner_by_name('your-summoner-name') lol.get_games(id) # Or set the ID globally for all future calls lol.set_summoner('bruntbear') lol.get_summoner_stats() lol.get_summoner_ranked_stats() # Access data through dictionaries try:
from leagueoflegends import LeagueOfLegends from leagueoflegends import RiotError import json lol = LeagueOfLegends('1201f800-aced-4abb-9083-714dcf58a36e') lol.set_api_region('br') print data
def __init__(self, key, region=__default_region): self.__api = LeagueOfLegends(key) self.__default_region = region
from leagueoflegends import LeagueOfLegends, RiotError from nose.tools import * import doctest import time import os doctest.testfile('README.md', verbose=False) api_key = os.environ['LOL_API_KEY'] lol = LeagueOfLegends(api_key) TEST_SUMMONER_ID = 5908 TEST_SUMMONER_NAME = "Dyrus" TEST_SUMMONER_IDS = [5908, 120546, 19347723] TEST_SUMMONER_NAMES = ["Dyrus", "RiotPhreak", "PhantomL0rd"] # Test region switching def test_region_set(): url = lol.set_api_region('euw') assert url == 'https://euw.api.pvp.net/api/lol/euw/v1.4/' url = lol.set_api_region('azeroth') assert url == None lol.set_api_region('na') # Test version switching def test_version_set():