#-*- coding: utf-8 -*-#!/usr/bin/env python#@Time : /6/15 17:12#@Desc :#@File : KingGlory.py#@Software: PyCharm
"""导入库"""
importurllibimportrequests,sys"""统一编码"""reload(sys)
sys.setdefaultencoding('utf-8')"""获取英雄图片"""
defDownloadHeroImage(url):
req=requests.get(url=url).json()
HeroNum=len(req['list'])print "一共有%d个英雄"%HeroNum
HeroImagesPath="HeroiImages"HeroList=req['list']for Hero inHeroList:
HeroImageUrl=Hero['cover']
HeroName=Hero['name']+".jpg"FileName=HeroImagesPath+"/"+HeroNameprint "正在下载%s的图片"%Hero['name']
urllib.urlretrieve(url=HeroImageUrl, filename=FileName)"""获取所有英雄的名字和ID"""
defHeroList(url):print '-'*100
print '\t\t\t\t欢迎使用《王者》出装小助手'
print '-'*100req=requests.get(url=url).json()
flag=0
HeroList=req['list']#for Hero in HeroList:
#flag+=1
#print "%s的ID为:%s"%(Hero["name"],Hero["hero_id"]),"\t"
#if flag==3:
#print "\n",""
#flag=0
returnHeroList"""获取并打印出装信息
Weapon所有武器的字典"""msg=''
defHeroInfo(url,WeaponInfo):
req= requests.get(url=url).json()#msg=''
msg='历史上的%s:%s'%(req['info']['name'],req['info']['history_intro'])#print "\n历史上的%s:\n %s"%(req['info']['name'],req['info']['history_intro'])
for eachEquipChoice in req['info']['equip_choice']:
msg+='\n'+(eachEquipChoice['title'])+':'+eachEquipChoice['description']print "\n%s:%s"%(eachEquipChoice["title"],eachEquipChoice["description"])
flag=0
totalPrice=0for eachWeapon in eachEquipChoice['list']:
flag+=1weapon=seekWeapon(eachWeapon['equip_id'],WeaponInfo)
weaponName=weapon[0]
weaponPrice=weapon[1]
msg+=('%s:%s'%(weaponName,weaponPrice)+'\t')print "%s:%s"%(weaponName,weaponPrice),"\t"
if flag==3:print "\n",""flag=0
totalPrice+=int(weaponPrice)
msg+=u'神装套件总计:'+str(totalPrice)#print "神装套件总计:%d"%totalPrice
returnmsg"""根据equip_id查询武器名字和价格
WeaponInfo保存所有武器的字典"""
defseekWeapon(equipid,weaponinfo):for weapon inweaponinfo:if weapon['equip_id']==str(equipid):
weaponname=weapon['name']
weaponprice=weapon['price']returnweaponname,weaponprice"""获取武器信息"""
defheroWeapon(url):
req=requests.get(url=url).json()
weaponList=req['list']returnweaponListif __name__ == '__main__':#英雄列表URL地址
heros_url = "/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"
#DownloadHeroImage(heros_url)
#武器URL地址
weapon_url = "/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"weaponInfo=heroWeapon(weapon_url)# HeroList=HeroList(heros_url)for Hero inHeroList:print "%s的ID为:%s"%(Hero["name"],Hero["hero_id"]),"\t"hero_id=Hero["hero_id"]
hero_url= "/wzry/hero/detail?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".format(
hero_id)
HeroInfo(hero_url,weaponInfo)
如果觉得《python小助手_Python实现王者荣耀小助手(二)》对你有帮助,请点赞、收藏,并留下你的观点哦!