Skip to main content

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

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

lcu-driver-0.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

lcu_driver-0.0.1-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

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