https://github.com/plutokekz/riotapiparser
A small script to parse the riot api documentation to generate json schema file, which get converted to pydantic models aka python dataclasses. For an eay and fast prototyping of api wrappers.
https://github.com/plutokekz/riotapiparser
bs4 code-generation json-schema league-of-legends legends-of-runeterra parser pydantic python riot-games-api tft valorant
Last synced: about 1 month ago
JSON representation
A small script to parse the riot api documentation to generate json schema file, which get converted to pydantic models aka python dataclasses. For an eay and fast prototyping of api wrappers.
- Host: GitHub
- URL: https://github.com/plutokekz/riotapiparser
- Owner: Plutokekz
- Created: 2022-04-11T09:29:07.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-10-25T21:03:24.000Z (over 3 years ago)
- Last Synced: 2026-05-06T02:11:23.568Z (about 1 month ago)
- Topics: bs4, code-generation, json-schema, league-of-legends, legends-of-runeterra, parser, pydantic, python, riot-games-api, tft, valorant
- Language: Python
- Homepage:
- Size: 66.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RiotApiParser
A small script to parse the riot api documentation to generate json schema file,
which get converted to pydantic models aka python dataclasses. For an eay and fast prototyping
of api wrappers.
### Installation
clone or downloade the repository and install the requirements
```bash
cd RiotApiParser
pip install -r requirements.txt
```
### Run
```cmd
python main.py -h
usage: main.py [-h] [-p PARSER] [-jp JSON_PATH] [-pp PYTHON_PATH] [-u URL]
optional arguments:
-h, --help show this help message and exit
-p PARSER, --parser PARSER
select a parser for bs4, default: lxml
-jp JSON_PATH, --jsonpath JSON_PATH
Path to store the json schema file, default: models
-pp PYTHON_PATH, --pythonpath PYTHON_PATH
Path to store the python file, default: python
-u URL, --url URL url to riot developers page with the api documentation, default: https://developer.riotgames.com/apis
```
````bash
python main.py
````
If the script run's with the default arguments, you got two folder models and python.
In the models' directory is the json schema located and in the python directory the generated
python files.
### Example
Parsing the website entry to json schema

````json
{
"title": "AccountDto",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"puuid": {
"type": "string"
},
"gameName": {
"type": "string",
"description": "This field may be excluded from the response if the account doesn't have a gameName."
},
"tagLine": {
"type": "string",
"description": "This field may be excluded from the response if the account doesn't have a tagLine."
}
}
}
````
Generating python code from the json schema
````python
# generated by datamodel-codegen:
# filename: AccountDto.json
# timestamp: 2022-04-11T09:10:43+00:00
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, Field
class AccountDto(BaseModel):
puuid: Optional[str] = None
gameName: Optional[str] = Field(
None,
description="This field may be excluded from the response if the account doesn't have a gameName.",
)
tagLine: Optional[str] = Field(
None,
description="This field may be excluded from the response if the account doesn't have a tagLine.",
)
````