Skip to content

Commit

Permalink
干员查询修复
Browse files Browse the repository at this point in the history
  • Loading branch information
IJNKAWAKAZE committed Jul 24, 2024
1 parent cf1c4cf commit ae07bea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
16 changes: 10 additions & 6 deletions src/plugins/operator/parse_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
})
}
})
Expand Down
6 changes: 2 additions & 4 deletions src/utils/arknights_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func updateData() {
}
// 重置
recruitOperatorList = nil

//operators
operatorsJson := RedisGet("operatorList")
json.Unmarshal([]byte(operatorsJson), &operators)
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 16 additions & 6 deletions src/utils/base_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ae07bea

Please sign in to comment.