没有项目描述
lcu-driver的Python项目详细描述
LCU驱动器
用于lcu api的python接口。仅支持Windows平台。灵感来自lcu-connector
下载
pip install lcu-driver
代码示例
每次运行应用程序时,更改为随机的中文图标。
fromjsonimportdumpsfromrandomimportrandintfromlcu_driverimportConnectorconnector=Connector()asyncdefset_random_icon():# random number of a chinese iconrandom_number=randint(50,78)# make the request to set the iconicon=awaitconnector.request('put','/lol-summoner/v1/current-summoner/icon',data=dumps({'profileIconId':random_number}))# if HTTP status code is 201 the icon was applied successfullyificon.status==201:print(f'Chinese icon number {random_number} was set correctly.')else:print('Unknown problem, the icon was not set.')# fired when LCU API is ready to be used@connector.eventasyncdefconnect():print('LCU API is ready to be used.')# check if the user is already logged into his accountsummoner=awaitconnector.request('get','/lol-summoner/v1/current-summoner')ifsummoner.status==200:data=awaitsummoner.json()# calls login method and update login.left_calls to 0# when login.left_calls is 0 the function can't be fired any more neither by websocket nor manuallyawaitlogin(None,None,data)else:print('Please login into your account to change your icon...')# fired when League Client is closed (or disconnected from websocket)@connector.eventasyncdefdisconnect():print('The client have been closed!')# subscribe to the login websocket event, and calls the function only one time@connector.ws_events(['/lol-summoner/v1/current-summoner'],event_types=['Update'],max_calls=1)asyncdeflogin(typ,uri,data):print('Logged as',data['displayName'])awaitset_random_icon()# opens websocket connection (may be used to wait until the client is closed)connector.listen()# starts everythingconnector.start()
类和方法
class连接器
初始化(自,*,循环=无)
- 循环
属性
PID
进程ID.协议 允许协议的元组。
端口
验证键
安装路径
地址
WS-U地址
方法
开始()
启动司机。
听()
在客户端关闭之前保持连接。(打开WebSocket连接)。
<;协同工作>;停止工作
优雅地停止WebSocket循环。
coroutine请求(方法:str,端点:str,**kwargs)
- 方法-http动词。
- endpoint-没有协议和主机名的资源url。
- **kwargs
- <aiohttp.ClientSession>.request-函数参数
- path-指向str.format()的别名
ws_事件(端点:list,*,事件类型:list,max_calls=-1)
- endpoints-uri列表。
- 事件类型-事件类型列表(创建、更新或删除)。
- {STR 1 } $ Max调用< <强> >最大事件事件函数可由WebSoCor或手动调用。将其设置为负数以删除限制。
内置库事件
连接
在LCU API启动时激发。断开 在客户端关闭时激发。