Skip to main content

Exports League of Legends Match History data using the RiotGames API

Project description

lolexport

Exports League of Legends Match History metadata using the RiotGames API

I don't play league of legends that often anymore, this is to export my entire match history so I can do some analysis as part of HPI. With group-and-termgraph

$ hpi query my.league.export -s | jq '.game_mode' -r | group-and-termgraph
ODYSSEY   :  3.00
ULTBOOK   : ▇▇ 12.00
GAMEMODEX : ▇▇▇▇ 29.00
NEXUSBLITZ: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 110.00
ARAM      : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 159.00
CLASSIC   : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 203.00
URF       : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 293.00
$ hpi query my.league.export -s | jq '.champion' -r | group-and-termgraph | tail -n 10
Rengar      : ▇▇▇▇▇ 17.00
TwistedFate : ▇▇▇▇▇ 17.00
Lux         : ▇▇▇▇▇▇ 20.00
Thresh      : ▇▇▇▇▇▇ 20.00
Bard        : ▇▇▇▇▇▇▇ 25.00
Riven       : ▇▇▇▇▇▇▇▇ 26.00
MasterYi    : ▇▇▇▇▇▇▇▇▇ 29.00
Gragas      : ▇▇▇▇▇▇▇▇▇ 30.00
Yasuo       : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 68.00
LeeSin      : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 159.00

Though, more interesting to me is that this tells me when/how long every match was, which means I can graph my activity.

I'm not sure how far back the match history goes. I've been playing on and off since 2015 but the history only goes back to 2018. May be a ~2/3 year limit, or that might just be when this API Version was supported/standardized.

Get an API key from here and put it in a JSON file, with the same format as ./api_key_example.json

Combines the results from matchlist_by_puuid and matches/by-puuid, and dumps all the info to a JSON file.

Installation

Requires at least python3.7

To install with pip, run:

pip install git+https://github.com/seanbreckenridge/lolexport

This is accessible as lolexport and using python3 -m lolexport

Usage

Theres 2 commands here, export (which does the majority of the work, exporting info from your matches to a JSON file) and then parse which takes that as input and extracts (what I consider to be) useful data from it.

Export

python3 -m lolexport export --help
Usage: lolexport export [OPTIONS]

  Download all of your match history

Options:
  -t, --to PATH            JSON file to dump export to  [required]
  -k, --api-key-file PATH  json file with api key  [required]
  -u, --username TEXT      league of legends summoner name  [required]
  -r, --region TEXT        league of legends region name  [required]
  --help                   Show this message and exit.

$ python3 -m lolexport export --to data.json --api-key-file ./api_key.json --username yourSummonnerName --region na1
[D 220226 19:27:00 export:44] Getting encrypted account id...
[D 220226 19:27:00 export:23] Got 100 matches from offset 100...
[D 220226 19:27:01 export:23] Got 100 matches from offset 200...
[D 220226 19:27:02 export:23] Got 100 matches from offset 300...
[D 220226 19:27:03 export:23] Got 3 matches from offset 400...
[D 220226 19:27:04 export:23] Got 0 matches from offset 500...
[D 220226 19:27:05 export:56] [1/303] Requesting match_id => NA1_4078236924
[D 220226 19:27:07 export:56] [2/303] Requesting match_id => NA1_4078245874
[D 220226 19:27:08 export:56] [3/303] Requesting match_id => NA1_4076309908
[D 220226 19:27:09 export:56] [4/303] Requesting match_id => NA1_4076197909
[D 220226 19:27:10 export:56] [5/303] Requesting match_id => NA1_4074607857
...
$ du -h data.json
9.2M	data.json

See here for region codes.

Merge

Takes multiple JSON files as input and loads them into memory, removing duplicates

$ python3 -m lolexport merge -u yourSummonnerName ~/data/league_of_legends/*.json
[D 220227 04:38:41 merge:152] Skipped 438 items, returning 809 items...
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.1.0 -- An enhanced Interactive Python. Type '?' for help.

Use res to access visit data
In [1]: res[0]._serialize()
Out[1]:
{'username': 'yourSummonnerName',
 'game_id': 3517403685,
 'won': False,
 'champion': 'Rammus',
 'game_started': datetime.datetime(2020, 8, 1, 18, 8, 30, tzinfo=datetime.timezone.utc),
 'game_ended': datetime.datetime(2020, 8, 1, 18, 25, 36, tzinfo=datetime.timezone.utc),
 'game_mode': 'NEXUSBLITZ'}

In [2]: res[0].raw
Out[2]: {'gameId': 3517403685, 'champion': {'name': 'Rammus', 'title': 'the Armordillo', 'blurb': 'Idolized by many, dismissed by some, mystifying to all, the curious being Rammus is an enigma. Protected by a spiked shell, he inspires increasingly disparate theories on his origin wherever he goes—from demigod, to sacred oracle, to a mere beast...', 'tags': ['Tank', 'Fighter'], 'partype': 'Mana'}, 'queue': None, 'season': 13, 'role': 'DUO_SUPPORT', 'lane': 'NONE', 'gameCreation': 1596305310886, 'gameDuration': 1026, 'map': 'Nexus Blitz', 'gameMode': 'NEXUSBLITZ'

Parsing

This command is deprecated, it was used for the v4 API -- v5 now includes the relevant static data

The export above saves all the data, but I'm not interested in tons of the specifics, so lolexport.parse is what I'd use, you're free to parse the data however.

python3 -m lolexport parse --help
Usage: lolexport parse [OPTIONS]

  Parses the exported data to attach additional metadata

  Prints results to STDOUT

Options:
  -f, --from PATH  exported JSON file to process  [required]
  --help           Show this message and exit.

It prints the parsed data to STDOUT, so you can do:

python3 -m lolexport parse --from ./data.json > parsed.json

That removes some of the fields I'm not interested in, and replaces champion/map/queue IDs with their names.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lolexport-0.1.3.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

lolexport-0.1.3-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file lolexport-0.1.3.tar.gz.

File metadata

  • Download URL: lolexport-0.1.3.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for lolexport-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5274a1bf94e5669616ed0771a2065ec1a6d143f4eba2f4f5260b0a6e75a1b1fc
MD5 834927015544e285e712eb997302d073
BLAKE2b-256 3311657e82fcb78765f8652dc55887a9bb84cd8bf133a803d96713783a7fab99

See more details on using hashes here.

File details

Details for the file lolexport-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: lolexport-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for lolexport-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b733e8f4e73d6165ba96ad1e4847b928b8c6848c259372c3a0a2cdf8768f9409
MD5 c8549caefb53aa3cc51f2d576233db21
BLAKE2b-256 46f828a2500229cc8651f6aa90c85285a27f9f55f3a285cbba90f3fc10670e7f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page