利⽤Python制作王者战⼒查询以及⽪肤查看软件
根据下⾯的提供的王者荣耀最低战⼒查询的Python源码,使⽤PYQT5搭建了⼀个GUI,同时还可以看每个英雄⽪肤的⾼清图。
"""
当然在学习Python的道路上肯定会困难,没有好的学习资料,怎么去学习呢?
学习Python中有不明⽩推荐加⼊交流Q号:928946953
⾥有志同道合的⼩伙伴,互帮互助,⾥有不错的视频学习教程和PDF!
还有⼤⽜解答!
"""
import requests as r
import random
import json
def getMidStr(txt, txt_start, txt_end='', seeks=0, seeke=0):
"""取中间⽂本函数"""
try:
if txt_end or seeks or seeke:
pass
else:
raise 1
s_1 = txt.find(txt_start)
if s_1 == -1:
raise 1
l_1 = len(txt_start)
if txt_end:
s_2 = txt.find(txt_end, s_1)
if s_1 == -1 or s_2 == -1:
return False
return txt[s_1 + l_1:s_2]
if seeks:
return txt[s_1 - seeks:s_1]
if seeke:
return txt[s_1 + l_1:s_1 + l_1 + seeke]
except Exception:
return '传参错误或未到传参⽂本'
while True:
hero = input("输⼊需要查询的英雄:")
python怎么读取py文件if hero == "":
print("您输⼊⽆效")
elif hero == "0":
exit()
else:
source = r.get("s.wukongfenshen:9972/main/api/honour/wzpower/static/js/index.js?v=0." + str( random.randint(1000000, 9999999))).text
_json = getMidStr(source, "var dictAll = ", "}}") + "}}"
_json = json.loads(_json)
try:
_json[hero]
except KeyError as reason:
print("没有英雄:%s" % reason)
continue
title = _json[hero]["title"]
content = _json[hero]["content"]
print("英雄:%s" % title)
content = place(content, "<p><p>", "\n")
content = place(content, "<p> <p>", "\n")
content = place(content, "</p>", "\n")
content = place(content, "<p>", "")
print(content + "\n")
如果想更换主界⾯背景,修改第90⾏的图⽚路径即可。
pixmap.load("./image/199-bigskin-3.jpg")
搜索框输⼊想查询的英雄名称,带有⾃动补全。英雄查询失败,或者名字不正确,则会被提⽰
点击搜索,搜索时间有时较长有时较短,我也不知道为什么。结果界⾯如下,背景默认为原⽪⽪肤,可以移动⿏标位置到缩略图上,即可将该⽪肤设置为背景。
点击QQ头像即可切换到区
⿏标停留在地区上,则会显⽰所属省份或市级(该功能默认关闭,因为需调⽤百度地图api, 使⽤前要⾃
⼰去申请相应的 ak, 申请后将functions⽂件夹下get_detail_location.py 中的 ak 替换为⾃⼰的 ak 即可)
def get_detail_location(place_name):
ak = 'ckXXxxxxxxxxxxxxxxxxcO9' # 替换为⾃⼰申请的ak
url = "api.map.baidu/place/v2/suggestion" + \
f"?query={place_name}®ion={place_name}&city_limit=false&output=json&ak={ak}"
res = (url).json()
return res['result'][0]['province'] + res['result'][0]['city']
核⼼Python代码:
from multiprocessing import Pool
import sys
import time
from bs4 import BeautifulSoup
from PyQt5.QtGui import QBrush, QIcon, QMouseEvent, QPalette, QPixmap
from PyQt5.QtCore import pyqtSignal, Qt, QRect, QSize, QThread
from PyQt5.QtWidgets import QApplication, QCompleter, QGraphicsOpacityEffect, QGroupBox,\
QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout, QWidget
import requests
import sip
# 引⼊⾃定义组件
from custom_widgets.CustomQLabel import CustomQLabel
from custom_widgets.PowerDisplayArea import PowerDisplayArea
from custom_widgets.SkinBox import SkinBox
from custom_widgets.WarnMessagebox import WarnMessagebox
# 引⼊⾃定义函数
_detail_location import get_detail_location
_heroSkin_url import heroSkin, download_image_data
_power_information import get_power_info
# 读取qss⽂件并设置stylesheet
class QssTool:
@staticmethod
def set_qss(obj, filepath):
with open(filepath, 'r', encoding='utf-8') as f:
style = f.read()
obj.setStyleSheet(style)
class RunThread(QThread):
"""
该线程⽤于下载图⽚数据以及获取地名详情信息
该线程⽤于下载图⽚数据以及获取地名详情信息
"""
_signal = pyqtSignal(object)
def __init__(self, hero, qq_info, wx_info):
super(RunThread, self).__init__()
self.hero = hero
self.qq_info = qq_info
self.wx_info = wx_info
def __del__(self):
self.wait()
def run(self):
print('线程开始')
self.load_data(self.hero, self.qq_info, self.wx_info)
def load_data(self, hero, qq_info, wx_info):
"""
1. 调⽤ heroSkin 获取英雄⽪肤以及缩略图⽹址,然后在线程池中下载图⽚数据
2. 调⽤ get_detail_location 补全定位所在省份或者市级
:
param hero:
:param qq_info:
:param wx_info:
:return:
"""
small_skin, big_skin, num = heroSkin(hero) # 爬取⾼清⽪肤、缩略图⽹址,以及⽪肤数量 pool = Pool(2 * (num-1)) # 利⽤线程池下载⽪肤⾼清图以及缩放图数据
rl = pool.map(download_image_data, big_skin + small_skin)
pool.close() # 关闭进程池,不再接受新的进程
pool.join() # 主进程阻塞等待⼦进程的退出
img_data = rl
# 补全地区信息
qq_detail_place = [get_detail_location(qq_item['定位']) for qq_item in qq_info]
wx_detail_place = [get_detail_location(wx_item['定位']) for wx_item in wx_info]
return_data = {
'big_skin': img_data[:num],
'small_skin': img_data[num:],
'qq_detail_place': qq_detail_place,
'wx_detail_place': wx_detail_place,
'qq_info': qq_info,
'wx_info': wx_info,
}
self._it(return_data)
# 主程序
class App(QWidget):
def __init__(self, parent=None):
super(App, self).__init__(parent)
# 应⽤布局美化
QssTool.set_qss(self, 'beautify.qss')
self.setWindowTitle("王者战⼒查询")
# 设置窗⼝背景
pixmap = QPixmap()
pixmap.load("./image/199-bigskin-3.jpg")
pixmap = pixmap.scaled(960, 441, Qt.KeepAspectRatio, Qt.SmoothTransformation)
palette = QPalette()
palette.setBrush(QPalette.Background, QBrush(pixmap))
self.setPalette(palette)
self.mainLayout = QVBoxLayout(self)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.addStretch()
# 显⽰⽪肤头像的布局
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论