2017-06-20 21:27:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-06-20 22:34:18 +00:00
|
|
|
"fmt"
|
2017-06-20 21:27:14 +00:00
|
|
|
"strings"
|
|
|
|
|
2017-06-23 16:22:48 +00:00
|
|
|
"github.com/aerogo/flow"
|
2017-06-20 21:27:14 +00:00
|
|
|
"github.com/animenotifier/arn"
|
2017-06-20 22:34:18 +00:00
|
|
|
"github.com/fatih/color"
|
2017-06-20 21:27:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-06-20 22:34:18 +00:00
|
|
|
color.Yellow("Updating search index")
|
|
|
|
|
2017-06-23 16:22:48 +00:00
|
|
|
flow.Parallel(updateAnimeIndex, updateUserIndex)
|
2017-06-20 22:34:18 +00:00
|
|
|
|
|
|
|
color.Green("Finished.")
|
2017-06-20 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func updateAnimeIndex() {
|
|
|
|
animeSearchIndex := arn.NewSearchIndex()
|
|
|
|
|
|
|
|
// Anime
|
2017-06-27 10:39:41 +00:00
|
|
|
animeStream, err := arn.StreamAnime()
|
2017-06-20 21:27:14 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for anime := range animeStream {
|
2017-06-28 00:51:11 +00:00
|
|
|
if anime.Title.Romaji != "" {
|
|
|
|
animeSearchIndex.TextToID[strings.ToLower(anime.Title.Romaji)] = anime.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
if anime.Title.English != "" {
|
|
|
|
animeSearchIndex.TextToID[strings.ToLower(anime.Title.English)] = anime.ID
|
2017-06-20 22:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if anime.Title.Japanese != "" {
|
|
|
|
animeSearchIndex.TextToID[anime.Title.Japanese] = anime.ID
|
|
|
|
}
|
2017-06-20 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 22:34:18 +00:00
|
|
|
fmt.Println(len(animeSearchIndex.TextToID), "anime titles")
|
|
|
|
|
2017-06-20 21:27:14 +00:00
|
|
|
// Save in database
|
|
|
|
err = arn.DB.Set("SearchIndex", "Anime", animeSearchIndex)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUserIndex() {
|
|
|
|
userSearchIndex := arn.NewSearchIndex()
|
|
|
|
|
|
|
|
// Users
|
2017-06-27 12:38:36 +00:00
|
|
|
userStream, err := arn.StreamUsers()
|
2017-06-20 21:27:14 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for user := range userStream {
|
2017-06-20 22:34:18 +00:00
|
|
|
if user.IsActive() && user.Nick != "" {
|
|
|
|
userSearchIndex.TextToID[strings.ToLower(user.Nick)] = user.ID
|
|
|
|
}
|
2017-06-20 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 22:34:18 +00:00
|
|
|
fmt.Println(len(userSearchIndex.TextToID), "user names")
|
|
|
|
|
2017-06-20 21:27:14 +00:00
|
|
|
// Save in database
|
|
|
|
err = arn.DB.Set("SearchIndex", "User", userSearchIndex)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|