吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5007|回复: 11
收起左侧

[Python 转载] 英雄联盟lcuapi的应用【自动寻找,接受对局,一键设置符文,取opgg符文信息】

  [复制链接]
Nettos 发表于 2022-7-31 18:44
本帖最后由 Nettos 于 2022-7-31 20:35 编辑

小白刚学习python
功能界面展示:
gn.png
     获取召唤师信息
     自动寻找接受对局
     一键配置符文
     下载符文到本地(https://www.op.gg/_next/data/4PrRvjK6-FMwqJEfhArSq/champions/' + name + '/' + position + '/runes.json)
     4PrRvjK6-FMwqJEfhArSq这一段是opgg定时会随机成其他字符串,请问各位有解决方法么
【main】
[Python] 纯文本查看 复制代码
import json
import runes_path
import os
import re
import sys
import threading
from time import sleep
import requests
import urllib3

# 屏蔽安全警告
urllib3.disable_warnings()
# 设置Falg线程参数
event = threading.Event()


class AuthToken(object):
    """获取LOL端口及密钥信息"""

    def __init__(self):
        self.url = None
        self.host = '127.0.0.1'
        self.agreement = 'https://'
        self.port = None
        self.token = None

    def get_info(self):
        f = os.popen('WMIC PROCESS WHERE name="LeagueClientUx.exe" GET commandline', 'r')
        d = f.read()
        self.port = re.findall(r'--app-port=(\d*)', d)[0]
        self.token = re.findall(r'--remoting-auth-token=(.*?)"', d)[0]
        # port_token = app_port + app_token
        self.url = self.agreement + 'riot:' + str(self.token) + '@' + self.host + ':' + str(self.port)
        return self.url


class LcuApi(AuthToken):
    @staticmethod
    def tips():
        print('-' * 15 + '功能选择' + '-' * 15)
        print('第一次打开应用需要手动选择更新符文信息,否则会导致符文配置功能无法使用')
        print('请勿频繁更新符文,会导致IP被限制访问opgg,第一次打开程序更新一次,后面可以每天选择更新一次!')
        print("1、获取召唤师信息")
        print("2、开启自动寻找与接受对局")
        print("3、关闭自动寻找与接受对局")
        print("4、一键配置符文")
        print("5、更新符文信息")
        print("0、退出系统")

    def client_info(self):
        """取客户端状态信息"""
        while True:
            rest = "/lol-gameflow/v1/gameflow-phase"
            text = requests.get(self.url + rest, verify=False)
            info_list = text.json()
            event.wait()
            if info_list == 'ReadyCheck':
                lcu.accept_match()
            elif info_list == 'Lobby':
                lcu.auto_match()
            sleep(1)

    def friend(self):
        """获取好友信息"""
        rest = "/lol-summoner/v1/current-summoner"
        request = requests.get(self.url + rest, verify=False).json()
        print(f'用户名:{request["displayName"]}')
        print(f'等  级:{request["summonerLevel"]}')
        print(f'经  验:{request["xpSinceLastLevel"]} / {request["xpUntilNextLevel"]}')
        print(f'用户id:{request["accountId"]}')
        money = requests.get(self.url + '/lol-store/v1/wallet', verify=False).json()
        print(f'蓝色精粹:{money["rp"]}')
        print(f'橙色精粹:{money["ip"]}')
        # print(request['displayName'])

    def auto_match(self):
        """寻找对局"""
        rest = "/lol-lobby/v2/lobby/matchmaking/search"
        requests.post(self.url + rest, verify=False)

    def accept_match(self):
        """接受对局"""
        rest = "/lol-matchmaking/v1/ready-check/accept"
        requests.post(self.url + rest, verify=False)

    def get_rune(self):
        """一键配置符文"""
        # 获取选择的英雄
        static_hero = requests.get(
            self.url + '/lol-lobby-team-builder/champ-select/v1/session',
            verify=False).json()
        judge_info = str(static_hero).find('progress')
        print(judge_info)
        if judge_info == -1:
            # 没有找到progress,为匹配对局
            print(static_hero)
            print('测试信息')
            try:
                name = []
                # static_hero['localPlayerCellId'] 大于4是红色方,小于等于4是蓝色方
                if static_hero['localPlayerCellId'] > 4:
                    for i in static_hero['myTeam']:
                        name.append(i)
                    choice_hero = (name[static_hero['localPlayerCellId'] - 5]['championId'])
                else:
                    for i in static_hero['myTeam']:
                        name.append(i)
                    print(name[static_hero['localPlayerCellId']]['championId'])
                    choice_hero = (name[static_hero['localPlayerCellId']]['championId'])
            except:
                print('请选择英雄后在配置符文')
                return
        else:
            lock_hero = requests.get(self.url + '/lol-champ-select-legacy/v1/session', verify=False).json()  # 找到progress,为自定义对局
            try:
                for i in lock_hero['actions']:
                    for j in i:
                        hero_id = j
                print(hero_id['championId'])
                choice_hero = hero_id['championId']
            except:
                print('请在选择英雄的时候在配置符文')
                return
        # 获取所有英雄信息
        hero_list = requests.get(
            self.url + '/lol-game-data/assets/v1/champion-summary.json',
            verify=False).json()
        # print(hero_list)
        for i in hero_list:
            if choice_hero == i['id']:
                print(i['id'])
                print(i['alias'])
                try:
                    file_rune = open('opgg/' + str(i['alias']).lower() + '.data')
                    file_runes = eval(file_rune.read())
                    primarystyleId = file_runes[0]['primary_page_id']
                    selectedperkids = file_runes[0]['primary_rune_ids'] + file_runes[0]['secondary_rune_ids'] + \
                                      file_runes[0]['stat_mod_ids']
                    substyleid = file_runes[0]['secondary_page_id']
                    # 取所有符文页:/lol-perks/v1/pages
                    # 取当前符文页:/lol-perks/v1/currentpage
                    rest = "/lol-perks/v1/currentpage"
                    text = requests.get(self.url + rest, verify=False)
                    info_rune = text.json()
                    rune_id = str(info_rune['id'])
                    add_del_rune = "/lol-perks/v1/pages"
                    if info_rune['isDeletable']:
                        # 删除符文:/lol-perks/v1/pages/     delete
                        requests.delete(self.url + add_del_rune + '/' + rune_id, verify=False)
                        print('检测到默认符文页,执行删除新建')
                        # 设置符文:/lol-perks/v1/pages      post
                        requests.post(self.url + add_del_rune, data=json.dumps(
                            {'name': i['name'], 'primaryStyleId': primarystyleId, 'selectedPerkIds': selectedperkids,
                             'subStyleId': substyleid}), verify=False).json()
                    else:
                        print('不存在默认符文页,直接新建!')
                        requests.post(self.url + add_del_rune, data=json.dumps(
                            {'name':  i['name'], 'primaryStyleId': primarystyleId, 'selectedPerkIds': selectedperkids,
                             'subStyleId': substyleid}), verify=False).json()
                except:
                    print('您的符文列表没有更新,或者更新失败,请查看opgg文件夹中的data文件是否有数据')
                    return
        else:
            print('请锁定英雄后在配置符文')

    def test_info(self):
        rest = '/lol-game-data/assets/v1/champion-summary.json'
        request = requests.get(self.url + rest, verify=False)
        info_list = request.json()
        print(info_list)


if __name__ == '__main__':
    lcu = LcuApi()

    try:
        lcu.get_info()
    except Exception as res:
        print(f'错误信息:{res},退出!')
        sys.exit()
    client_thread = threading.Thread(target=lcu.client_info, daemon=True)
    client_thread.start()

    while True:
        # os.system('cls')
        lcu.tips()
        try:
            user_put = int(input("请选择:"))
        except Exception as res:
            print(f'错误信息:{res},请选择正确的功能')
            continue
        if user_put == 1:
            lcu.friend()
        elif user_put == 2:
            # 让子线程停止堵塞
            event.set()
            os.popen('title 自动寻找与接受对局:已开启')
        elif user_put == 3:
            # 让子线程开启堵塞
            event.clear()
            os.popen('title 自动寻找与接受对局:已关闭')
        elif user_put == 4:
            lcu.get_rune()
        elif user_put == 5:
            runes_path.start_updata_rune()
            print('符文更新成功!')
        elif user_put == 9:
            print(lcu.get_info())
        elif user_put == 0:
            break

【runes_path】
[Python] 纯文本查看 复制代码
import os
import threading
import jsonpath
import requests

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}


class Runes(object):
    def rune(self, name, position):
        response = requests.get(
            'https://www.op.gg/_next/data/4PrRvjK6-FMwqJEfhArSq/champions/' + name + '/' + position + '/runes.json',
            headers=headers).json()
        res = jsonpath.jsonpath(response, '$..runes')
        info_data = open('opgg/' + name + '.data', 'w')
        info_data.write(str(res[0]))
        info_data.close()

    def hero(self):
        """
        写英雄名称到文件
        :return:
        """
        try:
            os.mkdir('opgg')
        except Exception as res:
            print('目标文件夹已存在')
        response = requests.get(
            'https://www.op.gg/_next/data/4PrRvjK6-FMwqJEfhArSq/champions.json?region=global&tier=all',
            headers=headers).json()
        name = jsonpath.jsonpath(response, '$.pageProps.championMetaList.key')
        position = jsonpath.jsonpath(response, '$.pageProps.championMetaList.positions[0].name')
        for name_lists, poss in zip(name, position):
            hero_data = open('opgg/' + name_lists + '.data', 'w')
            hero_data.write(poss)
            hero_data.close()


run = Runes()


def start_updata_rune():
    run.hero()
    name_list = os.listdir('opgg')
    for i in name_list:
        index = i.rfind('.')
        names = i[:index]
        file_name = open('opgg/' + i, 'r')
        positions = file_name.read()
        runes_thread = threading.Thread(target=run.rune, args=(names, positions))
        runes_thread.start()
        file_name.close()


发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| Nettos 发表于 2022-8-1 15:27
qylisten 发表于 2022-8-1 09:29
就想知道这个有什么用,要怎么用?


https://anyhg.lanzouy.com/iBgKW08tg4jc

这个是我编译好的文件,直接打开就能使用,记得用管理员身份运行
kingsxue89 发表于 2022-8-1 07:33
RemMai 发表于 2022-8-1 08:44
qylisten 发表于 2022-8-1 09:29
就想知道这个有什么用,要怎么用?
virsnow 发表于 2022-9-29 14:35
感谢楼主分享,谢谢分享学习知识
我嗳破解 发表于 2022-9-29 21:20
很棒的工具,加油加油
rxlrxl012 发表于 2022-10-3 22:27
好像失效了,不能用了
songqing 发表于 2022-10-20 16:37
大佬 你会写lol伤害统计?
灵剑丹心 发表于 2023-10-25 09:44
op.gg/_next/data  后面会变化的那段数据有固定的方法获取吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 20:09

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表