Created
January 9, 2014 15:15
-
-
Save Rejna/8335634 to your computer and use it in GitHub Desktop.
Python Riot API wrapper and request sender.
This file contains hidden or 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
| class MasteryPages(object): | |
| def __init__(self, summonerId, pages): | |
| self.summonerId = summonerId | |
| self.pages = pages | |
| class MasteryPage(object): | |
| def __init__(self, id, name, current, talents): | |
| self.id = id | |
| self.name = name | |
| self.current = current | |
| self.talents = talents | |
| class Talent(object): | |
| def __init__(self, id, name, rank): | |
| self.id = id | |
| self.name = name | |
| self.rank = rank |
This file contains hidden or 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
| class RecentGames(object): | |
| def __init__(self, summonerId, games): | |
| self.summonerId = summonerId | |
| self.games = games | |
| class Game(object): | |
| def __init__(self, championId, createDate, fellowPlayers, gameId, gameMode, gameType, invalid, level, mapId, spell1, spell2, statistics, subType, teamId): | |
| self.championId = championId | |
| self.createDate = createDate | |
| self.fellowPlayers = fellowPlayers | |
| self.gameId = gameId | |
| self.gameMode = gameMode | |
| self.gameType = gameType | |
| self.invalid = invalid | |
| self.level = level | |
| self.mapId = mapId | |
| self.spell1 = spell1 | |
| self.spell2 = spell2 | |
| self.statistics = statistics | |
| self.subType = subType | |
| self.teamId = teamId | |
| class Player(object): | |
| def __init__(self, summonerId, championId, teamId): | |
| self.summonerId = summonerId | |
| self.championId = championId | |
| self.teamId = teamId | |
| class RawStat(object): | |
| def __init__(self, id, name, value): | |
| self.id = id | |
| self.name = name | |
| self.value = value |
This file contains hidden or 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
| class RunePages(object): | |
| def __init__(self, summonerId, pages): | |
| self.summonerId = summonerId | |
| self.pages = pages | |
| class RunePage(object): | |
| def __init__(self, id, name, current, slots): | |
| self.id = id | |
| self.name = name | |
| self.current = current | |
| self.slots = slots | |
| class RuneSlot(object): | |
| def __init__(self, id, rune): | |
| self.id = id | |
| self.rune = rune | |
| class Rune(object): | |
| def __init__(self, id, name, description, tier): | |
| self.id = id | |
| self.name = name | |
| self.description = description | |
| self.tier = tier |
This file contains hidden or 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
| from datetime import datetime | |
| class Summoner(object): | |
| def __init__(self, id, name, profileIconId, summonnerLevel, revisionDate): | |
| self.id = id | |
| self.name = name | |
| self.profileIconId = profileIconId | |
| self.summonerLevel = summonnerLevel | |
| self.revisionDate = datetime.fromtimestamp(revisionDate / 1e3) | |
| def __str__(self): | |
| return "Name: %s\nID: %d\nProfileIconId: %d\nSummonerLevel: %d\nRevisionDate: %s" % (self.name, self.id, self.profileIconId, self.summonerLevel, self.revisionDate) |
This file contains hidden or 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
| from gi.repository import Gtk | |
| import Requests | |
| s = Requests.GetSummonerByName("eune", "Rejna") | |
| print(Requests.GetLeague("eune", str(s.id))) |
This file contains hidden or 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
| import urllib.request, Wrapper, json | |
| key = "2fd18e36-698e-4757-b401-2bf43c119f9a" | |
| address = "https://prod.api.pvp.net/api/lol/" | |
| version = "v1.2" | |
| version2 = "v2.2" | |
| def GetSummonerByName(region, name): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/summoner/by-name/"+name+"?api_key="+key) | |
| return json.loads(r.read().decode('utf-8'), object_hook=Wrapper.asSummoner) | |
| def GetSummonerById(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/summoner/"+ident+"?api_key="+key) | |
| return json.loads(r.read().decode('utf-8'), object_hook=Wrapper.asSummoner) | |
| def GetSummonerRunes(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/summoner/"+ident+"/runes/?api_key="+key) | |
| return Wrapper.asRunePages(json.loads(r.read().decode('utf-8'))) | |
| def GetSummonerMasteries(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/summoner/"+ident+"/masteries/?api_key="+key) | |
| return Wrapper.asMasteryPages(json.loads(r.read().decode('utf-8'))) | |
| def GetRecentGames(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/game/by-summoner/"+ident+"/recent?api_key="+key) | |
| return r.read().decode('utf-8') | |
| def GetLeague(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version2 + "/league/by-summoner/"+ident+"?api_key="+key) | |
| return r.read().decode('utf-8') | |
| def GetRankedStats(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/stats/by-summoner/"+ident+"/ranked?api_key="+key) | |
| return r.read().decode('utf-8') | |
| def GetSummaryStats(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/stats/by-summoner/"+ident+"/summary?api_key="+key) | |
| return r.read().decode('utf-8') | |
| def GetTeam(region, ident): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version2 + "/team/by-summoner/"+ident+"?api_key="+key) | |
| return r.read().decode('utf-8') | |
| def GetChampions(region): | |
| global key, address, version | |
| r = urllib.request.urlopen(address+region+"/" + version + "/champion?api_key="+key) | |
| return r.read().decode('utf-8') |
This file contains hidden or 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
| import Summoner, json, Runes, Masteries | |
| def asSummoner(dct): | |
| return Summoner.Summoner(dct['id'], dct['name'], dct['profileIconId'], dct['summonerLevel'], dct['revisionDate']) | |
| def asRunePages(dct): | |
| r = [] | |
| for p in dct['pages']: | |
| r.append(asRunePage(json.loads(json.JSONEncoder().encode(p)))) | |
| return Runes.RunePages(dct['summonerId'], r) | |
| def asRunePage(dct): | |
| r = [] | |
| for d in dct['slots']: | |
| r.append(asSlot(json.loads(json.JSONEncoder().encode(d)))) | |
| return Runes.RunePage(dct['id'], dct['name'], dct['current'], r) | |
| def asSlot(dct): | |
| return Runes.RuneSlot(dct['runeSlotId'], asRune(json.loads(json.JSONEncoder().encode(dct['rune'])))) | |
| def asRune(dct): | |
| return Runes.Rune(dct['id'], dct['name'], dct['description'], dct['tier']) | |
| def asMasteryPages(dct): | |
| r = [] | |
| for p in dct['pages']: | |
| r.append(asMasteryPage(json.loads(json.JSONEncoder().encode(p)))) | |
| return Masteries.MasteryPages(dct['summonerId'], r) | |
| def asMasteryPage(dct): | |
| r = [] | |
| for t in dct['talents']: | |
| r.append(asTalent(json.loads(json.JSONEncoder().encode(t)))) | |
| return Masteries.MasteryPage(dct['id'], dct['name'], dct['current'], r) | |
| def asTalent(dct): | |
| return Masteries.Talent(dct['id'], dct['name'], dct['rank']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment