1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| import requests import subprocess from datetime import datetime
class LCU:
def __init__(self): ''' init params ''' self.port = None self.host = '127.0.0.1' self.token = None self.protocol = 'https' self.url = None self.pid = None def getParam(self): ''' From https://github.com/minhluu2000/Project-Lego and changed a little Get necessary for client-specific info through CommandLine '''
raw_output = subprocess.check_output( ['wmic', 'PROCESS', 'WHERE', "name='LeagueClientUx.exe'", 'GET', 'commandline']).decode('gbk') app_port = raw_output.split('--app-port=')[-1].split(' ')[0].strip('\"') auth_token = raw_output.split('--remoting-auth-token=')[-1].split(' ')[0].strip('\"') url = self.protocol + '://' + 'riot:' + auth_token + '@' + self.host + ':' + app_port return app_port, auth_token, url
def init(self): ''' Init the instance ''' while True: if not self.checkProcess(): print('未检测到LeagueClient.exe') else: self.pid = self.checkProcess() self.port, self.token, self.url = self.getParam() break def giftablefriends(self): ''' /lol-store/v1/giftablefriends :return: [ { "friendsSince": "2015-06-06 19:51:10", "nick": "53263468", "oldFriends": true, "summonerId": 4012653853 }, .... ] ''' rest = "/lol-store/v1/giftablefriends" request = requests.get(self.url + rest, verify=False) infolist = request.json() return infolist
def getFriendDate(self, reverse=False): infolist = self.giftablefriends() date_now_tuple = datetime.now().timetuple() date_now = datetime(date_now_tuple.tm_year, date_now_tuple.tm_mon, date_now_tuple.tm_mday) for infodict in infolist: date = infodict['friendsSince'] date_old_tuple = datetime.strptime(date, '%Y-%m-%d %H:%M:%S').timetuple() date_old = datetime(date_old_tuple.tm_year, date_old_tuple.tm_mon, date_old_tuple.tm_mday) interval = (date_now-date_old).days infodict['interval'] = interval infolist.sort(key=lambda profile:profile['interval'], reverse=False) print(infolist) for infodict in infolist: date = infodict['friendsSince'] nick = infodict['nick'] interval = infodict['interval'] print(f'你和 {nick} 在 {date} 成为了好友, 距今已经 {interval}天')
lcu = LCU() lcu.init() lcu.getFriendDate()
|