No project description provided
Project description
lcu-driver
Python interface for LCU API. Only support Windows platform. Inspired in lcu-connector
Download
-
pip install lcu-driver
-
pip install git+https://github.com/sousa-andre/lcu-driver.git
Code example
Subclassing Connector:
import lcu_driver
class MyConnector(lcu_driver.Connector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.subscribe_event('OnJsonApiEvent_lol-summoner_v1_current-summoner')
@staticmethod
def connect(process, api):
con.subscribe_event('OnJsonApiEvent_lol-summoner_v1_current-summoner')
response = api.fetch('get', '/lol-summoner/v1/current-summoner')
if response.status_code == 200:
data = response.json()
print('You are already logged as {}.'.format(data['displayName']))
else:
print('The client is already opened, please login now.')
@staticmethod
def disconnect():
print('The client has been closed!')
@staticmethod
def message(data):
if 'accountId' in data['data']:
print('Logging in as {}.'.format(data['data']['displayName']))
con = MyConnector()
con.start()
Using decorators:
import lcu_driver
con = lcu_driver.Connector()
@con.event
def connect(process, api):
response = api.fetch('get', '/lol-summoner/v1/current-summoner')
if response.status_code == 200:
data = response.json()
print('You are already logged as {}.'.format(data['displayName']))
else:
print('The client is already opened, please login now.')
@con.event
def disconnect():
print('The client has been closed!')
@con.event
def message(data):
if 'accountId' in data['data']:
print('Logging in as {}.'.format(data['data']['displayName']))
con.start()
Classes and methods
class Connector
-
__init__(keep_running: bool = False, wait_for_client: bool = True, connect_via_websocket: bool = False)
- keep_running - After disconnect will keep looking for other clients.
- wait_for_client - Block execution until find a running client.
- connect_via_websocket - Start websocket connection.
Methods
-
subscribe_event(*events: str)
Entitle the events to be subscribed by the websocket connection.
-
start()
Start looking for client using the settings defined in the constructor.
Events
-
connect
<func>(process: ProcessDTO, api: APIDTO)
Fired when LCU API start. -
disconnect
<func>()
Fired when the client is closed. -
message
<func>(data: dict)
Fired when a websocket event occurs.
class ProcessDTO
-
__init__(**kwargs)
class APIDTO
-
__init__(**kwargs)
Methods
-
fetch(method: str, endpoint: str, **kwargs) -> requests.request
- method - HTTP verb
- endpoint - Resource URL without protocol and host name.
- **kwargs
- request.request - function arguments
- path - Alias to str.format()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lcu-driver-0.0.1.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for lcu_driver-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8329c8cb5b0b07ccbb0a812dc5de1c85bacf8060e19fb3e2cc8b0622f98735e2 |
|
MD5 | 6fa8343862d3b16591f88b4178ba3f39 |
|
BLAKE2b-256 | aa813700c3a9ea73ce209db57704cebda8e8bbc9aa68103f2e87a588d7eae285 |