PK!׬^88lcu_connectorpy/__init__.pyfrom .connect import Connector __all__ = ['Connector'] PK!bVVlcu_connectorpy/connect.pyimport sys import psutil import time from pathlib import Path from watchdog import events from watchdog.observers import Observer from typing import Tuple, Callable, Optional class Lock: """Parses the data in the lock file and formats the result""" def __init__(self, path: Path): self.path = path self.data = { 'name': None, 'id': None, 'port': None, 'password': None, 'protocol': None } self.load() def load(self) -> dict: """Load the lock file, store the results, and return the stored data""" if self.path.exists(): data = self.path.read_text().split(':') self.data = {k: v for k, v in zip(self.data, data)} else: self.data = {k: None for k in self.data} return self.data @property def ready(self) -> bool: return all(self.data.values()) class LeagueClient: """Handles locating the executable and lock file. Platform independent.""" name = "LeagueClient." + 'exe' if sys.platform.startswith('win') else 'app' def __init__(self): self.reset() def __get_process(self) -> psutil.Process: for p in psutil.process_iter(): if self.name == p.name(): return p def __get_lock(self) -> Lock: if self.process is None: return for file in self.process.open_files(): if file.path.endswith('lockfile'): return Lock(Path(file.path)) def reset(self): """Look for the process and lock file again""" self.process = self.__get_process() self.lock = self.__get_lock() def wait(self): """Block until a process and lock file have been found""" while not self.ready: self.reset() time.sleep(1) @property def ready(self) -> bool: return bool(self.process and self.lock and self.lock.ready) class FileSentry(events.FileSystemEventHandler): def __init__(self, path: Path, callback: Callable): super().__init__() self.path = path self.callback = callback self.observer = Observer() self.observer.schedule(self, self.path.parent) def __del__(self): self.observer.stop() def on_any_event(self, event): if Path(event.src_path) == self.path: self.callback() def start(self): self.observer.start() class Connector: """ Manager for getting info required to connect to the League Client. example:: ``` import requests from lcu_connectorpy import Connector conn = Connector() conn.start() r = requests.get( f'{conn.url}/Help', auth=conn.auth, headers={'Accept': 'application/json'} ) print(r.json()) ``` """ address = '127.0.0.1' username = 'riot' port: Optional[str] = None password: Optional[str] = None protocol: Optional[str] = None id: Optional[str] = None def __init__(self): self.client = LeagueClient() self.sentry: Optional[FileSentry] = None def update(self): for k, v in self.client.lock.load().items(): setattr(self, k, v) def start(self): """Start watching for the client. Blocks until found.""" self.client.wait() self.update() self.sentry = FileSentry(self.client.lock.path, self.update) @property def connected(self) -> bool: """Established connection, data is ready.""" return self.client.ready @property def url(self) -> str: """A url using the current lock file data""" return f'{self.protocol}://{self.address}:{self.port}' @property def auth(self) -> Tuple[str]: """A tuple (user, password) with the latest credentials""" return (self.username, self.password) PK!H-ZZ#0lcu_connectorpy-1.0.5.dist-info/entry_points.txtN+I/N.,()JOrl..PK!*͚88'lcu_connectorpy-1.0.5.dist-info/LICENSE The MIT License (MIT) Copyright (c) 2019 Noah Corona Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTU%lcu_connectorpy-1.0.5.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H3j(lcu_connectorpy-1.0.5.dist-info/METADATATR0}WhɌ8xHx CK:-퀰7 wp }a]1xr)X'.!ERV YHElRrPQ<Oδ>:cɈC-!4<{sLe`^)RE9\ԡ2Y dRp#%>6'OA" S_mN[` <9RXpdp|e`oEdΉIczz>Cc iwG&VgK)TF\e%/Ux{| qm[l;fQk2>SU(؋X'Hy/1=I)c^Y6=LV}J^ h'>3 +L*8nʇ ѷqS=Wգ i P=W>W2&whBZx$kX*4O N01!777.'FC8ϋ⃇Qt*j*Ҫ)B]4[u!cц:W"uD w6zhe{͆78]lޟ~˻oFksWNUR+ PK!HdR&lcu_connectorpy-1.0.5.dist-info/RECORD1s0( PbJYrQ!PzNs/M[Vex=<#D) 59֌jok4@*f-O {GCƑYm%cD?/01WVqq.z_6& ?s6F2~zy xΩSiZCׯݮ>7{ 5 kb,3&?"Yqwnw˔UӏY*,/L 2[@fȕ/PK!׬^88lcu_connectorpy/__init__.pyPK!bVVqlcu_connectorpy/connect.pyPK!H-ZZ#0lcu_connectorpy-1.0.5.dist-info/entry_points.txtPK!*͚88'klcu_connectorpy-1.0.5.dist-info/LICENSEPK!HڽTU%lcu_connectorpy-1.0.5.dist-info/WHEELPK!H3j(lcu_connectorpy-1.0.5.dist-info/METADATAPK!HdR&/lcu_connectorpy-1.0.5.dist-info/RECORDPKA