Files
tiennm99 5cff47f1ba fix: use MediaWiki API for wiki scraping to bypass Cloudflare
Direct wiki page requests return 403 due to Cloudflare JS challenge.
Switch to MediaWiki parse API which returns rendered HTML without
blocking. Also match img[alt='Official'] in lane detection.
2026-04-05 00:14:13 +07:00

47 lines
1.1 KiB
Go

package parser
import (
"fmt"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
)
// EnrichReleaseDates fetches the LoL Wiki to add release year to each champion.
func EnrichReleaseDates(champions []ChampionResult) ([]ChampionResult, error) {
doc, err := fetchWikiDoc("List_of_champions")
if err != nil {
return nil, fmt.Errorf("fetching wiki champion list: %w", err)
}
// Build a name-to-index map for O(1) lookups.
nameIndex := buildNameIndex(champions)
// The first <tbody> contains the champion list table.
doc.Find("tbody").First().Find("tr").Each(func(_ int, row *goquery.Selection) {
cols := row.Find("td")
if cols.Length() == 0 {
return
}
name := strings.TrimSpace(cols.Eq(1).Find("a").AttrOr("title", ""))
name = strings.ReplaceAll(name, "/LoL", "")
dateText := strings.TrimSpace(cols.Eq(3).Text())
parts := strings.Split(dateText, "-")
yearStr := parts[len(parts)-1]
year, err := strconv.Atoi(yearStr)
if err != nil {
return
}
if idx, ok := nameIndex[name]; ok {
champions[idx].ReleaseDate = year
}
})
return champions, nil
}