From ae07bea933a9418fba556c287abdcf929c0a3fcd Mon Sep 17 00:00:00 2001 From: Tenko Date: Wed, 24 Jul 2024 09:20:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B2=E5=91=98=E6=9F=A5=E8=AF=A2=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/operator/parse_operator.go | 16 ++++++++++------ src/utils/arknights_utils.go | 6 ++---- src/utils/base_utils.go | 22 ++++++++++++++++------ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/plugins/operator/parse_operator.go b/src/plugins/operator/parse_operator.go index dccc8f7..188ce34 100644 --- a/src/plugins/operator/parse_operator.go +++ b/src/plugins/operator/parse_operator.go @@ -158,12 +158,16 @@ func ParseOperator(name string) Operator { if selection.Text() == "后勤技能" { selection.NextFilteredUntil(".wikitable", "h2").Each(func(j int, selection *goquery.Selection) { var buildingSkill BuildingSkill - buildingSkill.Evolve = selection.Find("td").Eq(0).Text() - img, _ := selection.Find("td").Eq(1).Children().Attr("data-src") - buildingSkill.Icon = "https:" + img - buildingSkill.Name = selection.Find("td").Eq(2).Text() - buildingSkill.Desc = strings.ReplaceAll(selection.Find("td").Eq(4).Text(), "\n", "") - buildingSkills = append(buildingSkills, buildingSkill) + selection.Find("td").Each(func(k int, selection *goquery.Selection) { + if k%5 == 0 { + buildingSkill.Evolve = selection.Text() + img, _ := selection.Next().Children().Attr("data-src") + buildingSkill.Icon = "https:" + img + buildingSkill.Name = selection.Next().Next().Text() + buildingSkill.Desc = strings.ReplaceAll(selection.Next().Next().Next().Next().Text(), "\n", "") + buildingSkills = append(buildingSkills, buildingSkill) + } + }) }) } }) diff --git a/src/utils/arknights_utils.go b/src/utils/arknights_utils.go index 5381015..a866a21 100644 --- a/src/utils/arknights_utils.go +++ b/src/utils/arknights_utils.go @@ -77,7 +77,7 @@ func updateData() { } // 重置 recruitOperatorList = nil - + //operators operatorsJson := RedisGet("operatorList") json.Unmarshal([]byte(operatorsJson), &operators) @@ -138,17 +138,15 @@ func fetchEnemiesData() ([]pair, suffixtree.GST) { } func GetOperatorByName(name string) Operator { updateData() - return operatorMap[name] + return operatorMap[strings.ToLower(name)] } func GetOperatorsByName(name string) []Operator { updateData() var operatorList []Operator for _, op := range operatorTree.Search(strings.ToLower(name)) { - print(operators[op].Name) operatorList = append(operatorList, operators[op]) } - println() return operatorList } diff --git a/src/utils/base_utils.go b/src/utils/base_utils.go index ba0e645..cf90f80 100644 --- a/src/utils/base_utils.go +++ b/src/utils/base_utils.go @@ -302,13 +302,23 @@ func Md5(str string) string { } func GetImg(url string) []byte { - resp, err := http.Get(url) - if err != nil { - log.Println("获取图片失败", err) - return nil + var resp *http.Response + var pic []byte + times := 0 + for times < 3 { + resp1, err := http.Get(url) + resp = resp1 + if err != nil { + log.Println("获取图片失败", err) + times++ + continue + } + pic, _ = io.ReadAll(resp.Body) + break + } + if resp != nil { + defer resp.Body.Close() } - pic, _ := io.ReadAll(resp.Body) - defer resp.Body.Close() return pic }