This commit is contained in:
2025-12-31 16:06:58 +07:00
commit ce230479c7
21 changed files with 797 additions and 0 deletions

54
internal/as.go Normal file
View File

@@ -0,0 +1,54 @@
package internal
import (
"encoding/json"
"fmt"
"hakushi-crawl/api"
"os"
"sync"
)
func SaveDataASEvent(locale string) error {
listItem, err := api.GetListASEventApi()
if err != nil {
return err
}
mapItemDetail := make(map[string]*any)
var mu sync.Mutex
jobs := make(chan string)
wg := sync.WaitGroup{}
workerCount := 12
for range workerCount {
wg.Go(func() {
for itemId := range jobs {
itemDetail, err := api.GetASEventInfoApi(itemId, locale)
if err != nil || itemDetail == nil {
continue
}
mu.Lock()
mapItemDetail[itemId] = itemDetail
mu.Unlock()
}
})
}
for itemId := range listItem {
jobs <- itemId
}
close(jobs)
wg.Wait()
fileName := fmt.Sprintf("as.%s.json", locale)
data, err := json.Marshal(mapItemDetail)
if err != nil {
return err
}
return os.WriteFile(fileName, data, 0644)
}