from PIL import Image from PIL import ImageFilter from PIL import ImageEnhance from PIL import ImageDraw, ImageFont from datetime import datetime, timedelta import pytz import os import random import json from Vechile import Vechile_Character_Query from Player_Query import Character_Query class Specific_query(): async def txt_reader(self): #def txt_reader(self): with open(r"C:\Cq-http\NoneBot\Git_Plugins\QQbot\GGou7.txt", "r", encoding='gbk') as file: lines = file.read().strip("'").strip('"') lines = lines.replace("\n", "") lines = lines.replace("\t", "") lines = lines.strip("'") lines = json.loads(lines) # lines = lines.strip() return lines async def select_vehicle(self, Vehicle_BasicData, Select): #def select_vehicle(self, Vechile_BasicDate, Select): """landVehicleData = Vechile_BasicDate["landVehicleData"]["vehicleData"] waterVehicleData = Vechile_BasicDate["waterVehicleData"]["vehicleData"] otherVehicleData = Vechile_BasicDate["otherVehicleData"]["vehicleData"] airVehicleData = Vechile_BasicDate["airVehicleData"]["vehicleData"] date_list = [landVehicleData, waterVehicleData, otherVehicleData, airVehicleData] text = [] output = [] for b in range(0, len(date_list)): for i in range(0, len(date_list[b])): mid = date_list[b][i] partial_dict = {k: mid[k] for k in list(mid.keys())} text.append(partial_dict) #print(text) objective = [item for item in text if item["name"] == Select] return objective""" landVehicleData = Vehicle_BasicData["landVehicleData"]["vehicleData"] waterVehicleData = Vehicle_BasicData["waterVehicleData"]["vehicleData"] otherVehicleData = Vehicle_BasicData["otherVehicleData"]["vehicleData"] airVehicleData = Vehicle_BasicData["airVehicleData"]["vehicleData"] data_list = [landVehicleData, waterVehicleData, otherVehicleData, airVehicleData] for category in data_list: for vehicle in category: ##print(vehicle) if vehicle["engName"] == Select: return [vehicle] # 返回包含该车辆的列表,与之前返回类型一致 # 没有找到则返回空列表 return [] async def vechile_img(self, date, Vechile_BasicDate, sorting_data, num, mode='kill'): #def vechile_img(self, date, Vechile_BasicDate, sorting_data, num, mode='kill'): # 加载图片 file_path = os.path.dirname(os.path.abspath(__file__)) """ Player_query_Source_dir = os.path.join(file_path, "Charter_Sundy_Query") icon_dir = os.path.join(file_path, "Vechile_query\download") Source_dir = os.path.join(file_path, "Vechile_query\Source") Output_dir = os.path.join(file_path, "Vechile_query\Output") screen1_dir = ( os.path.join(file_path, "Vechile_query\screen1") ) screen2_dir = ( os.path.join(file_path, "Vechile_query\screen2") )""" file_path = os.path.dirname(os.path.abspath(__file__)) Player_query_Source_dir = str(file_path + "/Charter_Sundy_Query") icon_dir = str(file_path + "/Vechile_query/download") Source_dir = str(file_path + "/Vechile_query/Source") #Output_dir = str(file_path + "/Vechile_query/Output") screen1_dir = str(file_path + "/Vechile_query/screen1") screen2_dir = str(file_path + "/Vechile_query/screen2") bruh = "wrel.png" by_path = "love.png" ad_path = "ad_test.png" botton_path = "上面的丁真.png" Logo_path = "顶部LOGO.png" lable_path = "ID框.png" tr_path = "地球共和国.png" vs_path = "瓦努主权国.png" nc_path = "新联邦.png" nso_path = "纳能特工.png" level_path = "战斗等级底图.png" asp1_path = "asp1.png" asp2_path = "asp2.png" asp3_path = "asp3.png" online_path = "在线状态.png" offline_path = "离线状态.png" online_none_path = "无历史数据在线状态.png" offline_none_path = "无历史数据离线状态.png" money_path = "证书数量.png" sol_path = "索泰克.png" eme_path = "艾莫若德.png" con_path = "康纳利.png" cob_path = "柯伯特.png" mil_path = "米勒.png" other_path = "其他数据底图.png" tr_botton_path = "地球共和国背景.png" vs_botton_path = "瓦努主权国背景.png" nc_botton_path = "新联邦背景.png" nso_botton_path = "纳能特工背景.png" message_path = '缩写含义.png' screen_kill = "kill.png" screen_hit = "hit.png" screen_fire = "fire.png" screen_kps = "spk.png" screen_acc = "acc.png" screen_hpk = "hpk.png" screen_time = "time.png" screen_dmg = "dmg.png" screen_spm = "spm.png" up_path = r"/home/bot/QQbot/Charter_Sundy_Query/步兵武器列表/对比状态/从低到高.png" down_path = r"/home/bot/QQbot/Charter_Sundy_Query/步兵武器列表/对比状态/从高到低.png" judou_heavy = "judou-ui-cn-heavy.ttf" judou_heavyit = "judou-ui-cn-heavyitalic.ttf" judou_blod = "judou-bold.ttc" judou_media = "judou-medium.ttc" spc_flag = 0 ## ## message = Image.open(os.path.join( Source_dir, message_path)).convert("RGBA") #ad = Image.open(os.path.join(Source_dir, ad_path)).convert("RGBA") by = Image.open(os.path.join(Source_dir, by_path)).convert("RGBA") botton = Image.open(os.path.join( Source_dir, botton_path)).convert("RGBA") Logo = Image.open(os.path.join(Source_dir, Logo_path)).convert("RGBA") lable = Image.open(os.path.join( Source_dir, lable_path)).convert("RGBA") tr_icon = Image.open(os.path.join(Source_dir, tr_path)).convert("RGBA") vs_icon = Image.open(os.path.join(Source_dir, vs_path)).convert("RGBA") nc_icon = Image.open(os.path.join(Source_dir, nc_path)).convert("RGBA") nso_icon = Image.open(os.path.join( Source_dir, nso_path)).convert("RGBA") tr_botton = Image.open(os.path.join( Source_dir, tr_botton_path)).convert("RGBA") vs_botton = Image.open(os.path.join( Source_dir, vs_botton_path)).convert("RGBA") nc_botton = Image.open(os.path.join( Source_dir, nc_botton_path)).convert("RGBA") nso_botton = Image.open(os.path.join( Source_dir, nso_botton_path)).convert("RGBA") Soltech = Image.open(os.path.join( Source_dir, sol_path)).convert("RGBA") Miller = Image.open(os.path.join(Source_dir, mil_path)).convert("RGBA") Cobalt = Image.open(os.path.join(Source_dir, cob_path)).convert("RGBA") Connery = Image.open(os.path.join( Source_dir, con_path)).convert("RGBA") Emerald = Image.open(os.path.join( Source_dir, eme_path)).convert("RGBA") level_icon = Image.open(os.path.join( Source_dir, level_path)).convert("RGBA") asp1_icon = Image.open(os.path.join( Source_dir, asp1_path)).convert("RGBA") asp2_icon = Image.open(os.path.join( Source_dir, asp2_path)).convert("RGBA") asp3_icon = Image.open(os.path.join( Source_dir, asp3_path)).convert("RGBA") online = Image.open(os.path.join( Source_dir, online_path)).convert("RGBA") offline = Image.open(os.path.join( Source_dir, offline_path)).convert("RGBA") money_icon = Image.open(os.path.join( Source_dir, money_path)).convert("RGBA") other_icon = Image.open(os.path.join( Source_dir, other_path)).convert("RGBA") if mode == 'kill': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") elif mode == 'death': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") elif mode == 'kdr': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") elif mode == 'kpm': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") elif mode == 'hpk': article = Image.open(os.path.join(Source_dir, up_path)).convert("RGBA") elif mode == 'ivi': article = Image.open(os.path.join(Source_dir, up_path)).convert("RGBA") elif mode == 'hsr': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") elif mode == 'acc': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") elif mode == 'time': article = Image.open(os.path.join(Source_dir, down_path)).convert("RGBA") Title = ImageFont.truetype( (os.path.join(Source_dir, judou_blod)), 88, ) Numttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 240, ) No_ver_Name_ttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 308, ) Ver_NickName_ttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 264, ) Ver_ChartName_ttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 88, ) content = ImageFont.truetype( (os.path.join(Source_dir, judou_blod)), 52, ) status_time = ImageFont.truetype( ((os.path.join(Source_dir,judou_heavy))), 88, ) text_lable = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 24, ) heavyit = ImageFont.truetype( (os.path.join(Source_dir, judou_heavyit)), 88, ) width, height = botton.size logo_w, logo_h = Logo.size logo_r, logo_g, logo_b, logo_a = Logo.split() lable_r, lable_g, lable_b, lable_a = lable.split() level_r, level_g, level_b, level_a = level_icon.split() asp1_r, asp1_g, asp1_b, asp1_a = asp1_icon.split() asp2_r, asp2_g, asp2_b, asp2_a = asp2_icon.split() asp3_r, asp3_g, asp3_b, asp3_a = asp3_icon.split() online_r, online_g, online_b, online_a = online.split() offline_r, offline_g, offline_b, offline_a = offline.split() tr_botton_r, tr_botton_g, tr_botton_b, tr_botton_a = tr_botton.split() vs_botton_r, vs_botton_g, vs_botton_b, vs_botton_a = vs_botton.split() nc_botton_r, nc_botton_g, nc_botton_b, nc_botton_a = nc_botton.split() nso_botton_r, nso_botton_g, nso_botton_b, nso_botton_a = nso_botton.split() Soltech_r, Soltech_g, Soltech_b, Soltech_a = Soltech.split() Miller_r, Miller_g, Miller_b, Miller_a = Miller.split() Cobalt_r, Cobalt_g, Cobalt_b, Cobalt_a = Cobalt.split() Connery_r, Connery_g, Connery_b, Connery_a = Connery.split() Emerald_r, Emerald_g, Emerald_b, Emerald_a = Emerald.split() money_r, money_g, money_b, money_a = money_icon.split() other_r, other_g, other_b, other_a = other_icon.split() tr_r, tr_g, tr_b, tr_a = tr_icon.split() vs_r, vs_g, vs_b, vs_a = vs_icon.split() nc_r, nc_g, nc_b, nc_a = nc_icon.split() nso_r, nso_g, nso_b, nso_a = nso_icon.split() article_r, article_g, article_b, article_a = article.split() message_r, message_g, message_b, message_a = message.split() by_r, by_g, by_b, by_a = by.split() # 基础信息 Character_BasicDate = date['basicInfo'] charactername = Character_BasicDate["characterFullName"] outfitAlias = Character_BasicDate["outfitAlias"] outfitName = Character_BasicDate["outfitName"] factionId = Character_BasicDate["factionId"] serverName = Character_BasicDate["worldName"] money = str(Character_BasicDate["availableCertCount"]) battleRank = Character_BasicDate["battleRank"] aspRank = Character_BasicDate["aspRank"] FullName = Character_BasicDate["characterFullName"] # Character_Server = Character_BasicDate['Server'] # Character_ = Character_BasicDate[''] asplevel = Character_BasicDate["aspRank"] online = Character_BasicDate["online"] if outfitName == None: outfitName = '' try: title = str("[" + outfitAlias + "]" + " " + FullName) except: title = FullName lv = str("Lv." + str(battleRank)) off = "已离线" off_time = "" on_time = "" on = "已在线" w_on_time, h_on_time = Title.getsize(on_time) w_off_time, h_off_time = Title.getsize(off_time) w_outfitName, h_outfitName = content.getsize(str(outfitName)) date_common = Image.new("RGBA", (width, height), (0,0,0,0)) date_common.paste(botton, (0, 0)) #date_common.show()#上部数据 w_on_time, h_on_time = Title.getsize(on_time) w_off_time, h_off_time = Title.getsize(off_time) #判断是否认证,并生成与总览相同的头图 Sundy_auth = False user_message = None chart_msg = date['basicInfo']['characterFullName'] file_path_csv = os.path.join(os.path.dirname(__file__), r"csv/character.csv") auth_dict = await Character_Query().csv_Verified_User(file_path_csv)#异步 if chart_msg in auth_dict.values(): Sundy_auth = True matching_keys = [key for key, value in auth_dict.items() if value == chart_msg] #print(matching_keys) ver_chart_id = int(matching_keys[0]) csv_file_nickname = os.path.join(os.path.dirname(__file__), r"csv/nickname.csv") nickname_csv = await Character_Query().read_csv_to_list(csv_file_nickname) #print(nickname_csv) chart_list = await Character_Query().find_id(ver_chart_id,nickname_csv) ver_charactername = chart_list[1] else: Sundy_auth = False Online_flag = date['basicInfo']['online'] lastLoginfo = date['latestSessionInfo']['latestLoginDate'] lastLogout = date['latestSessionInfo']['latestLogoutDate'] try: if Online_flag == True : logintimeline = (lastLoginfo)/1000 logintime = datetime.fromtimestamp(logintimeline) formatted_time = logintime.strftime("%Y-%m-%d %H:%M:%S") elif Online_flag == False : Logouttimeline = (lastLogout)/1000 Logouttime = datetime.fromtimestamp(Logouttimeline) formatted_time = Logouttime.strftime("%Y-%m-%d %H:%M:%S") except: formatted_time = '数据库无记录' ##### if Online_flag == True:#QQbot\Charter_Sundy_Query\步兵武器列表\状态\在线文字背景.png #Status_light = os.path.join(Player_query_Source_dir,'步兵武器列表/状态/在线圆点.png') Status_light = Player_query_Source_dir + '/步兵武器列表/状态/在线圆点.png' status_text = 'ONLINE NOW ' + formatted_time #BackGround_path = os.path.join(Player_query_Source_dir,'步兵武器列表/状态/在线文字背景.png') BackGround_path = Player_query_Source_dir + '/步兵武器列表/状态/在线文字背景.png' color = (0,252,155) else: #Status_light = os.path.join(Player_query_Source_dir,'步兵武器列表\状态\离线圆点.png') Status_light = Player_query_Source_dir + '/步兵武器列表/状态/离线圆点.png' status_text = 'OFFLINE At ' + formatted_time #BackGround_path = os.path.join(Player_query_Source_dir,'步兵武器列表\状态\离线文字背景.png') #BackGround_path = Player_query_Source_dir + '/步兵武器列表/状态/离线文字背景.png' color = (255,255,255) light = Image.open(Status_light).convert("RGBA") try: light_shadow = Image.open(BackGround_path).convert("RGBA") except: on_light_shadow = False if on_light_shadow != False: w,h = status_time.getsize(status_text) r,g,b,a = light.split() date_common.paste(light,(2000-w-220,700+20),mask=a) r,g,b,a = light_shadow.split() date_common.paste(light_shadow,(2000-w-820,700-20),mask=a) else: w,h = status_time.getsize(status_text) r,g,b,a = light.split() date_common.paste(light,(2000-w-220,700+20),mask=a) date_common_pic = ImageDraw.Draw(date_common) date_common_pic.text(((2000-w-100),700),str(status_text),fill=(255,255,255),font=status_time) #根据验证状态写不同样式的名字 if Sundy_auth == False : w_tit,h_tit = No_ver_Name_ttf.getsize(chart_msg) if w_tit + 200 > 2000: No_ver_Name_ttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 280, ) w_tit,h_tit = No_ver_Name_ttf.getsize(chart_msg) if w_tit + 200 > 2000: No_ver_Name_ttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 240, ) w_tit,h_tit = No_ver_Name_ttf.getsize(chart_msg) if w_tit + 200 > 2000: No_ver_Name_ttf = ImageFont.truetype( (os.path.join(Source_dir, judou_heavy)), 240, ) w_tit,h_tit = No_ver_Name_ttf.getsize(chart_msg) x_No_ver_Name = 2000 - w_tit -100 date_common_pic.text( (x_No_ver_Name, 250), chart_msg, fill=(255,255,255), font=No_ver_Name_ttf ) else: w_tit,h_tit = Ver_NickName_ttf.getsize(ver_charactername) x_ver_nickName = 2000 - w_tit -100 date_common_pic.text( (x_ver_nickName, 120), ver_charactername, fill=(255,255,255), font=Ver_NickName_ttf ) w_tit,h_tit = Ver_ChartName_ttf.getsize(chart_msg) x_ver_nickName = 2000 - w_tit -100 date_common_pic.text( (x_ver_nickName, 410), chart_msg, fill=(255,255,255), font=Ver_ChartName_ttf ) # 添加文字 date_common_pic = ImageDraw.Draw(date_common) if mode == 'kill': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_kill)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_kill)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '击杀排序' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 #date_screen.show() elif mode == 'hit': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_hit)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_hit)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '命中次数排序' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 elif mode == 'fire': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_fire)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_fire)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '开火次数排序' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 elif mode == 'spk': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_kps)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_kps)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '击杀平均开火数' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 elif mode == 'hpk': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_hpk)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_hpk)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '击杀平均命中数' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 elif mode == 'acc': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_acc)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_acc)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '命中率排序' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 """ elif mode == 'hpk': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_hpk)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_hpk)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = mode w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据""" elif mode == 'dmg': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_dmg)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_dmg)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '伤害量排序' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 elif mode == 'time': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_time)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_time)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '累计使用时间排序' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 添加数据 elif mode == 'spm': # 打开特定底图 screen1 = Image.open(os.path.join( screen1_dir, screen_spm)).convert("RGBA") screen2 = Image.open(os.path.join( screen2_dir, screen_spm)).convert("RGBA") w_screen1, h_screen1 = screen1.size w_screen1r, w_screen1g, w_screen1b, w_screen1a = screen1.split() # 筛选标题和横幅 text = '分均平均得分数' w_text, h_text = Title.getsize(text) h_tiaotiao = 250 # 坐标数据 h_act = 40 hlist = [] for i in range(0, num): hf = h_tiaotiao + h_screen1 * i - h_act * (i + 1) hlist.append(hf) # 计算总高度并生成新画布 h_scr = h_screen1 * num + h_tiaotiao - h_act * (num) date_screen = Image.new("RGBA", (w_screen1, h_scr), (0,0,0,0)) date_screen.paste(article, (50, 0), article_a) # 区别排列数据展示框 for i in range(0, num): if i % 2 == 0: if i == 0: date_screen.paste(message, (0, hlist[i]), message_a) else: date_screen.paste(screen1, (0, hlist[i]), w_screen1a) else: date_screen.paste(screen2, (0, hlist[i]), w_screen1a) date_screen_pic = ImageDraw.Draw(date_screen) date_screen_pic.text( (((w_screen1 - w_text) / 2), 5), text, fill=(255,255,255), font=Title, ) # date_screen.paste(by, (0, hlist[-1]+h_screen1-h_act), by_a) # 敌前三的武器数据 # sorted_list = (sorted(Character_Battle_weaponStatList, key=lambda x: x['kill']))[-3:] # sorted_list = Character_Battle_weaponStatList[:(num-1)] sorted_list = sorting_data # sorted_list = (sorted(sorted_list1, key=lambda x: x['kill'])) for i in range(0, len(sorted_list)): kill = sorted_list[i]["kill"] kps = "%.2f" % sorted_list[i]["kps"] hit = sorted_list[i]["hit"] fire = sorted_list[i]["fire"] accuracy = sorted_list[i]["accuracy"] spm1 = sorted_list[i]["spm"] #懒得调了 spm = "%.2f" % spm1 if sorted_list[i]["hpk"] == ' ': hpk = ' ' else: hpk = "%.2f" % sorted_list[i]["hpk"] # 命中数量/击杀数量 if sorted_list[i]["playTime"] == ' ': playTime = ' ' dtime = ' ' else: playTime = int(((sorted_list[i]["playTime"]))) minutes, seconds = divmod(playTime, 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) dtime = f"{days}天 {hours}时 {minutes}分 {seconds}秒" imageID = sorted_list[i]["imageId"] name = sorted_list[i]["name"] if sorted_list[i]["hsr"] == ' ': dmg = ' ' else: damage = (sorted_list[i]["damage"])/10000 dmg = (("%.2f" % damage) + 'W') try: icon = str(imageID + ".png") except: icon = str('wrel.png') weapon_icondir = str(os.path.join(icon_dir, icon)) # 拆分名字 string_B = "" try: splitted = name.split(" ") string_A = splitted[0] # 获取第一个部分 string_B = ''.join(str(x)for x in splitted[1:]) # 获取第二个部分 except: string_A = name w_string_A, h_string_A = Title.getsize(str(string_A)) w_string_B, h_string_B = Title.getsize(str(string_B)) if w_string_A + w_string_B < 465: string_A = name string_B = '' w_string_A, h_string_A = Title.getsize(str(string_A)) w_string_B, h_string_B = Title.getsize(str(string_B)) # 计算参数 try: weapon = Image.open(weapon_icondir).convert("RGBA") except: weapon = Image.open(str(os.path.join(Source_dir, bruh))).convert("RGBA") weapon_r, weapon_g, weapon_b, weapon_a = weapon.split() w_kill, h_kill = heavyit.getsize(str(kill)) w_death, h_death = Title.getsize(str(fire)) w_hsr, h_hsr = Title.getsize(str(hit)) w_accuracy, h_accuracy = Title.getsize(str(accuracy)) w_kdr, h_kdr = Title.getsize(str(kps)) w_kpm, h_kpm = Title.getsize(str(dmg)) w_hpk, h_hpk = Title.getsize(str(hpk)) w_ivi, h_ivi = Title.getsize(str(spm)) w_playTime, h_playTime = Title.getsize(str(dtime)) interval = 860 (x, y) = weapon.size x_s = 400 # 定义缩小后的标准宽度 y_s = int(y * x_s / x) # 基于标准宽度计算缩小后的高度 weapon1 = weapon.resize((x_s, y_s), Image.ANTIALIAS) r, g, b, a = weapon1.split() Vechile_dir = Vechile_BasicDate[0]["imageId"] + '.png' Vechile_icondir = str(os.path.join(icon_dir, Vechile_dir)) try: Vechile_pic = Image.open(Vechile_icondir).convert("RGBA") except: Vechile_pic = Image.open(str(os.path.join(Source_dir, bruh))).convert("RGBA") Vechile1 = Vechile_pic.resize((x_s, y_s), Image.ANTIALIAS) vr, vg, vb, va = Vechile1.split() date_screen.paste(Vechile1, (110, (340 + interval + interval * i)), va) if weapon.size == (128, 128): date_screen.paste( weapon1, (110, (360 + interval + interval * i)), a) elif weapon.size == (400, 400): date_screen.paste( weapon1, (110, (360 + interval + interval * i)), a) else: date_screen.paste( weapon1, (110, (590 + interval + interval * i)), a) date_screen_pic.text( (20, 150 + interval + interval * i), str(i+1), fill=(255, 255, 255), # 255, 87, 23 font=Numttf, # heavyit ) date_screen_pic.text( ((850 + (370 - w_kill) / 2), 333 + interval + interval * i), str(kill), fill=(0, 0, 0), # 255, 87, 23 font=Title, # heavyit ) date_screen_pic.text( ((850 + (370 - w_death) / 2), 475 + interval + interval * i), str(fire), fill=(0, 0, 0), font=Title, ) date_screen_pic.text( ((850 + (370 - w_hsr) / 2), 617 + interval + interval * i), str(hit), fill=(0, 0, 0), font=Title, ) date_screen_pic.text( ((850 + (370 - w_accuracy) / 2), 753 + interval + interval * i), str(accuracy), fill=(0, 0, 0), font=Title, ) date_screen_pic.text( ((1540 + (370 - w_kdr) / 2), 333 + interval + interval * i), str(kps), fill=(0, 0, 0), font=Title, ) date_screen_pic.text( ((1540 + (370 - w_kpm) / 2), 475 + interval + interval * i), str(dmg), fill=(0, 0, 0), font=Title, ) date_screen_pic.text( ((1540 + (370 - w_hpk) / 2), 617 + interval + interval * i), str(hpk), fill=(0, 0, 0), font=Title, ) date_screen_pic.text( ((1540 + (370 - w_ivi) / 2), 753 + interval + interval * i), str(spm), fill=(0, 0, 0), font=Title, ) if w_string_A > 465: Title_s = ImageFont.truetype( (os.path.join(Source_dir, judou_blod)), 64, ) w_string_A, h_string_A = Title_s.getsize(str(string_A)) date_screen_pic.text( ((65 + (465 - w_string_A) / 2), 830 + interval + interval * i), str(string_A), fill=(255, 255, 255), font=Title_s, ) else: date_screen_pic.text( ((65 + (465 - w_string_A) / 2), 830 + interval + interval * i), str(string_A), fill=(255, 255, 255), font=Title, ) if w_string_B > 465: Title_s = ImageFont.truetype( (os.path.join(Source_dir, judou_blod)), 64, ) w_string_B, h_string_B = Title_s.getsize(str(string_B)) if w_string_B > 465: None else: date_screen_pic.text( ((65 + (465 - w_string_B) / 2), 920 + interval + interval * i), str(string_B), fill=(255, 255, 255), font=Title_s, ) else: date_screen_pic.text( ((65 + (465 - w_string_B) / 2), 920 + interval + interval * i), str(string_B), fill=(255, 255, 255), font=Title, ) date_screen_pic.text( ((1030 + (870 - w_playTime) / 2), 912 + interval + interval * i+3), str(dtime), fill=(0, 0, 0), font=Title, ) #date_screen.show() w_screen, h_screen = date_screen.size h = 900 + h_screen date1 = Image.new("RGBA", (w_screen1, h), (0,124,212,100)) sr, sg, sb, sa = date_screen.split() # 生成最终图 date1.paste(date_common, (0, 0)) date1.paste(date_screen, (0, 900), sa) # 保存 # date1.save('test.png') date2 = date1.convert("RGB") #date2 = date2.resize((w_date1, h_adlast), Image.ANTIALIAS) filename = str(charactername) + '_SpecVech.jpg' #Output_dir = os.path.join(file_path, "Charter_Sundy_Query/Output") Output_dir = r'/home/bot/QQbot/Charter_Sundy_Query/Output' output = os.path.join(Output_dir, filename) date2.save(output, "JPEG", quality=70, subsampling=0) return filename class sorting(): async def Data_sorting(self, vecheli_data, flag): #def Data_sorting(self, vecheli_data, flag): if flag == 'kill': sorted_list = ( sorted(vecheli_data, key=lambda x: x['kill'], reverse=True)) return sorted_list elif flag == 'hit': sorted_list = ( sorted(vecheli_data, key=lambda x: x['hit'], reverse=True)) return sorted_list elif flag == 'fire': sorted_list = ( sorted(vecheli_data, key=lambda x: x['fire'], reverse=True)) return sorted_list elif flag == 'kps': sorted_list = ( sorted(vecheli_data, key=lambda x: x['kps'], reverse=True)) return sorted_list elif flag == 'kpm': sorted_list = ( sorted(vecheli_data, key=lambda x: x['kpm'], reverse=True)) return sorted_list elif flag == 'acc': sorted_list = ( sorted(vecheli_data, key=lambda x: x['accuracy'], reverse=True)) return sorted_list elif flag == 'hpk': sorted_list = ( sorted(vecheli_data, key=lambda x: x['hpk'], reverse=True)) return sorted_list elif flag == 'spm': sorted_list = ( sorted(vecheli_data, key=lambda x: x['spm'], reverse=True)) return sorted_list elif flag == 'time': sorted_list = ( sorted(vecheli_data, key=lambda x: x['playTime'], reverse=True)) return sorted_list """ select_flag = '海盗战机' mode = 'spm' data = Specific_query().txt_reader() Vechile_BasicDate_ori = data["battleData"]['vehicleData'] factionId = data['basicInfo']['factionId'] playerdate = data['basicInfo'] Vechile_BasicDate = Specific_query().select_vehicle( Vechile_BasicDate_ori, Select=select_flag) Vechile_weapon_data = Vechile_BasicDate[0]['weaponStat'] sorting_data = sorting().Data_sorting(Vechile_weapon_data, mode) list_num = len(Vechile_weapon_data)+1 charactername = Specific_query().vechile_img( data, Vechile_BasicDate, sorting_data, list_num, mode) #print(charactername) """