Giter Club home page Giter Club logo

leagueoflegends-python's Introduction

leagueoflegends-python

This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.

###Quickstart

pip install leagueoflegends

from leagueoflegends import LeagueOfLegends, RiotError
lol = LeagueOfLegends('your-api-key')

# 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('your-summoner-name')
lol.get_summoner_stats()
lol.get_summoner_ranked_stats()

# Access data through dictionaries
try:
    teams = lol.get_summoner_teams()
    for t in teams:
        print t["name"]
        for m in t["roster"]["memberList"]:
            id = m["playerId"]
            print id
            print lol.get_summoner_by_id(id)["name"]
except RiotError, e:
    print e.error_msg

###Words

This is an unofficial Python Library for the official League of Legends API (Riot Developer API), wrapping HTTP calls into Python dictionaries.

Full documentation for Riot's RESTful API is here. Dictionaries returned by this library corresponds to the datatypes documented there.

Library code is distributed under the WTFPL. You are free to modify and redistribute. Attribution is a nice touch, and I'd love to hear what you get up to with this library.

###General Usage

The Riot Developer API does not support anonymous access. You must register for an API key with Riot before using this API.

from leagueoflegends import LeagueOfLegends
lol = LeagueOfLegends('your-api-key')

####get_champions (API Doc)

Returns a list of all champions. Optionally only return free to play champions.

champs = lol.get_champions(free_to_play=False)
for champ in champs:
    print champ["name"]

###Summoner-Specific Methods

####get_summoner_games (API Doc)

Returns a list of recent games played by a specific summoner, up to 10.

Takes a specific summoner_id (long) argument. If you want to query by summoner name, add a second lookup (see below).

games = lol.get_summoner_games(12345678)
for game in games:
    print game["championId"]

####get_summoner_leagues (API Doc)

Returns the leagues associated with a specific summoner ID.

leagues = lol.get_summoner_leagues(12345678)
for queue_type in leagues:
    print leagues[queue_type]["tier"]

####get_summoner_stats (API Doc)

Returns summary stats (aggregate over all champions) for a specific summoner ID.

stats = lol.get_summoner_stats(12345678)
for stat in stats:
    print stat["aggregatedStats"]["totalAssists"]

####get_summoner_ranked_stats (API Doc)

Returns aggregated stats, summarized per champion, from ranked matches. Includes statistics for Twisted Treeline and Summoner's Rift.

rankedstats = lol.get_summoner_ranked_stats(12345678)
for champ in stats:
    print champ["id"]

####get_summoner_by_id (API Doc)

Returns basic information about a specific summoner ID (name, level, etc).

summoner = lol.get_summoner_by_id(12345678)
print summoner["name"]

####get_summoner_by_name (API Doc)

Returns the same information as get_summoner_by_id but queried by name.

summoner = lol.get_summoner_by_name('RiotPhreak')
print summoner["id"]

####get_summoner

Convenience shortcut to the above two functions. Takes either an ID or a name and returns the summoner object.

summoner = lol.get_summoner('RiotPhreak')
print summoner["id"]

summoner = lol.get_summoner('12345678')
print summoner["name"]

####get_summoner_id_from_name

Convenience shortcut to retrieving a summoner ID given a specific name, as per the get_summoner_by_name example snippet above.

summoner_id = lol.get_summoner_by_name('RiotPhreak')
stats = lol.get_summoner_stats(summoner_id)
...

####get_summoner_names (API Doc)

Get up to 40 summoner names at once from a list of summoner IDs.

summoner_ids = [1234, 5678, 12345678]
summoner_names = lol.get_summoner_names(summoner_ids)
for summoner in summoner_names:
    print summoner["name"]

####get_summoner_masteries (API Doc)

Get mastery pages for a specific summoner ID.

masteries = lol.get_summoner_masteries(12345678)
for page in masteries:
    for talent in page["talents"]:
       print talent["name"]

####get_summoner_runes (API Doc)

Get rune pages for a specific summoner ID.

runes = lol.get_summoner_runes(12345678)
for page in runes:
    for slot in page["slots"]:
       print slot["rune"]["name"] + ' '\
           + slot["rune"]["description"]

####get_summoner_teams (API Doc)

Get team information for a specific summoner. Can return multiple teams.

teams = lol.get_summoner_teams(12345678)

for team in teams:
    print team["name"]

for team in teams:
    for match in t["matchHistory"]:
        total_wins += 1 and match["win"]
print total_wins

####set_summoner

Convenience function to set summoner ID from name. Summoner-specific functions can be called without an ID argument if this has been set.

lol.set_summoner("RiotPhreak")
lol.get_summoner_stats()
lol.get_summoner_teams()

####get_games, get_leagues, get_stats, get_ranked_stats

If you're tired of typing 'summoner', these convenience functions might help.

###Config

####set_api_region

Takes a region as argument and executes all further API calls against that region.

Valid regions: euw, eune, na, tr, br.

Note: not all API functions support all regions. Check Riot documentation if you run into weird errors. At time of writing, na, euw, eune regions are valid for all calls.

####set_api_version

Takes a version as argument, and sets it for future API calls. However, note that many API requests have the version hardcoded since there is variance between supported versions for each call. Where multiple versions of a specific endpoint are available, the newest version is used.

###Rate Limits

At time of writing, the Riot API limit is 10 requests every 10 seconds and 500 requests every 10 minutes. You will encounter a RiotError if you exceed this limit.

Consider your API request design wisely, and note that looking up a summoner ID from name is its own API call (although these queries are cached temporarily).

try:
    for summoner in very_long_summoner_list:
        lol.get_summoner_by_name(summoner)
except RiotError, e:
    print e.error_msg

###Tests

Tests are in test_leagueoflegends.py and the easiest way to run them is with Nose:

pip install nose
nosetests

leagueoflegends-python's People

Contributors

ramonsaraiva avatar jennielees avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.