学校实训的第三天(2)

王者荣耀助手(控制台输出的)
话不多说,直接上代码:

import requests
def init():
    #1.准备头部信息
    head = {'Accept-Charset': 'UTF-8',
            'Accept-Encoding': 'gzip,deflate',
            'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; MI 5 MIUI/V8.1.6.0.MAACNDI)',
            'X-Requested-With': 'XMLHttpRequest',
            'Content-type': 'application/x-www-form-urlencoded',
            'Connection': 'Keep-Alive',
            'Host': 'gamehelper.gm825.com'}

    #2.准备英雄列表的地址
    heros_list_url = 'http://gamehelper.gm825.com/wzry/hero/list?channel_id=90009a&app_id=h9044j&game_id=7622&game_name=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80&vcode=12.0.3&version_code=1203&cuid=2654CC14D2D3894DBF5808264AE2DAD7&ovr=6.0.1&device=Xiaomi_MI+5&net_type=1&client_id=1Yfyt44QSqu7PcVdDduBYQ%3D%3D&info_ms=fBzJ%2BCu4ZDAtl4CyHuZ%2FJQ%3D%3D&info_ma=XshbgIgi0V1HxXTqixI%2BKbgXtNtOP0%2Fn1WZtMWRWj5o%3D&mno=0&info_la=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&info_ci=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&mcc=0&clientversion=&bssid=VY%2BeiuZRJ%2FwaXmoLLVUrMODX1ZTf%2F2dzsWn2AOEM0I4%3D&os_level=23&os_id=dc451556fc0eeadb&resolution=1080_1920&dpi=480&client_ip=192.168.0.198&pdunid=a83d20d8'
    # 3.显示英雄列表
    show_heros_list(heros_list_url,head)
    # 11.查询英雄详细信息,输出
    hero_id = input('请输入查询英雄的ID:')
    hero_info_url = 'http://gamehelper.gm825.com/wzry/hero/detail?hero_id='+hero_id+'&channel_id=90009a&app_id=h9044j&game_id=7622&game_name=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80&vcode=12.0.3&version_code=1203&cuid=2654CC14D2D3894DBF5808264AE2DAD7&ovr=6.0.1&device=Xiaomi_MI+5&net_type=1&client_id=1Yfyt44QSqu7PcVdDduBYQ%3D%3D&info_ms=fBzJ%2BCu4ZDAtl4CyHuZ%2FJQ%3D%3D&info_ma=XshbgIgi0V1HxXTqixI%2BKbgXtNtOP0%2Fn1WZtMWRWj5o%3D&mno=0&info_la=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&info_ci=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&mcc=0&clientversion=&bssid=VY%2BeiuZRJ%2FwaXmoLLVUrMODX1ZTf%2F2dzsWn2AOEM0I4%3D&os_level=23&os_id=dc451556fc0eeadb&resolution=1080_1920&dpi=480&client_ip=192.168.0.198&pdunid=a83d20d8'
    show_hero_info(hero_info_url,head)

    #18.在继续
    yes = input('继续查询输入y,退出输入n')
    if yes == 'y':
        init()
    elif yes == 'n':
        print('END\n'*5)
        return
    else:
        print('你调皮了,请输入正确指令')
        init()

def show_heros_list(heros_list_url,head):
    #5.初始化页面
    print('*'*100)
    print('\t\t\t\t\t\t\t\t欢迎使用王者荣耀盗版助手')
    print('*'*100,end='\n')
    print('\t\t\t\t\t\t\t\t--英雄列表--',end='\n')

    #6.发起请求
    response = requests.get(url=heros_list_url,headers=head)
    if response.status_code ==200:
        #7.json():返回的json字符串 转换成 json格式的对象
        json = response.json()
        #print(json['request_id'])
        #8.通过name list获取value  json['name']
        flag = 0
        for hero in json['list']:
            #9.格式化字符:%s:插入一个string类型的值
            print('ID: %s 英雄名字: %s'%(hero['hero_id'],hero['name']),end='\t\t')
            #10.当flag递增到3时,跨行处理,初始为0
            flag += 1
            if flag == 3:
                print('\n')
                flag = 0
    else:
        print('盗版软件以后请勿使用---------')

#显示查询英雄的信息
def show_hero_info(hero_info_url,head):
    try:
        #11.查询英雄信息,输出
        json = requests.get(url=hero_info_url,headers=head).json()
        print('查询英雄:%s  别名:%s'%(json['info']['name'],json['info']['title']),end='\n\n' )
        print('历史介绍:\n %s' %(json['info']['history_intro']),end='\n\n')
        print('技能: ',end='\n')
        for skill in json['info']['skill_list']:
            print('名字: %s \n描述:%s \nTAG:%s'%(skill['name'],skill['description'],skill['tags']), end='\n\n')

        #12.查询推荐出装,并显示装备信息
        weapon_list_url = 'http://gamehelper.gm825.com/wzry/equip/list?channel_id=90009a&app_id=h9044j&game_id=7622&game_name=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80&vcode=12.0.3&version_code=1203&cuid=2654CC14D2D3894DBF5808264AE2DAD7&ovr=6.0.1&device=Xiaomi_MI+5&net_type=1&client_id=1Yfyt44QSqu7PcVdDduBYQ%3D%3D&info_ms=fBzJ%2BCu4ZDAtl4CyHuZ%2FJQ%3D%3D&info_ma=XshbgIgi0V1HxXTqixI%2BKbgXtNtOP0%2Fn1WZtMWRWj5o%3D&mno=0&info_la=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&info_ci=9AChHTMC3uW%2BfY8%2BCFhcFw%3D%3D&mcc=0&clientversion=&bssid=VY%2BeiuZRJ%2FwaXmoLLVUrMODX1ZTf%2F2dzsWn2AOEM0I4%3D&os_level=23&os_id=dc451556fc0eeadb&resolution=1080_1920&dpi=480&client_ip=192.168.0.198&pdunid=a83d20d8'
        weapon_json = requests.get(url=weapon_list_url,headers=head).json()
        #13.获取装备列表
        weapon_list = weapon_json['list']

        for choice in json['info']['equip_choice']:
            print('六神装介绍-%s:\n\t %s'%(choice['title'],choice['description']),end='\n\n')
            #14.循环是推荐装备列表
            totle_price = 0  # 价钱
            for equip_weapon in choice['list']:
                #15.装备商店的列表
                flag = 0
                for weapon in weapon_list:
                    #16.在遍历95件装备的时候:匹配推荐装备ID
                    if str(equip_weapon['equip_id']) == weapon['equip_id']:
                        weapon_name = weapon['name'] #获取装备名字
                        weapon_price = weapon['price'] #获取装备假期

                print('\t\t%s:%s'%(weapon_name,weapon_price))
                flag += 1
                if flag == 2 :
                    print('\n')
                    flag = 0
                totle_price += int(weapon_price)
            #17.输出六神装的总价钱 %d:int
            print('神装总价:%d'%(totle_price))
    except:
        print('没有该英雄,请重新输入')
        init()
#入口
if __name__ == '__main__':
    init()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值