Пример #1
0
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)
Пример #3
0
from leagueoflegends import LeagueOfLegends
from leagueoflegends import RiotError
import json

lol = LeagueOfLegends('1201f800-aced-4abb-9083-714dcf58a36e')

lol.set_api_region('br')

print data