From 46dd9f53a87a1246cdd3a5bb407d1fcd3b50e67e Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 1 Nov 2017 11:16:31 +0100 Subject: [PATCH] Removed old jobs --- jobs/forum-activity/forum-activity.go | 49 --------------- jobs/popular-anime/popular-anime.go | 62 ------------------- .../refresh-track-titles.go | 37 ----------- jobs/sync-characters/sync-characters.go | 3 +- .../sync-media-relations.go | 15 ++--- patches/add-balance/add-balance.go | 8 +-- 6 files changed, 8 insertions(+), 166 deletions(-) delete mode 100644 jobs/forum-activity/forum-activity.go delete mode 100644 jobs/popular-anime/popular-anime.go delete mode 100644 jobs/refresh-track-titles/refresh-track-titles.go diff --git a/jobs/forum-activity/forum-activity.go b/jobs/forum-activity/forum-activity.go deleted file mode 100644 index 3c2bb808..00000000 --- a/jobs/forum-activity/forum-activity.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -const maxEntries = 5 - -func main() { - color.Yellow("Caching list of forum activities") - - posts, err := arn.AllPosts() - arn.PanicOnError(err) - - threads, err := arn.AllThreads() - arn.PanicOnError(err) - - arn.SortPostsLatestFirst(posts) - arn.SortThreadsLatestFirst(threads) - - posts = arn.FilterPostsWithUniqueThreads(posts, maxEntries) - - postPostables := arn.ToPostables(posts) - threadPostables := arn.ToPostables(threads) - - allPostables := append(postPostables, threadPostables...) - - arn.SortPostablesLatestFirst(allPostables) - cachedPostables := arn.FilterPostablesWithUniqueThreads(allPostables, maxEntries) - - cache := &arn.ListOfMappedIDs{} - - for _, postable := range cachedPostables { - cache.Append(postable.Type(), postable.ID()) - } - - // // Debug log - // arn.PrettyPrint(cache) - - // // Try to resolve - // for _, r := range arn.ToPostables(cache.Resolve()) { - // color.Green(r.Title()) - // } - - arn.PanicOnError(arn.DB.Set("Cache", "forum activity", cache)) - - color.Green("Finished.") -} diff --git a/jobs/popular-anime/popular-anime.go b/jobs/popular-anime/popular-anime.go deleted file mode 100644 index 10a5483a..00000000 --- a/jobs/popular-anime/popular-anime.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - "sort" - - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -const maxPopularAnime = 10 - -// Note this is using the airing-anime as a template with modfications -// made to it. -func main() { - color.Yellow("Caching popular anime") - - // Fetch all anime - animeList, err := arn.AllAnime() - arn.PanicOnError(err) - - // Overall - sort.Slice(animeList, func(i, j int) bool { - return animeList[i].Rating.Overall > animeList[j].Rating.Overall - }) - - saveAs(animeList[:maxPopularAnime], "best anime overall") - - // Story - sort.Slice(animeList, func(i, j int) bool { - return animeList[i].Rating.Story > animeList[j].Rating.Story - }) - - saveAs(animeList[:maxPopularAnime], "best anime story") - - // Visuals - sort.Slice(animeList, func(i, j int) bool { - return animeList[i].Rating.Visuals > animeList[j].Rating.Visuals - }) - - saveAs(animeList[:maxPopularAnime], "best anime visuals") - - // Soundtrack - sort.Slice(animeList, func(i, j int) bool { - return animeList[i].Rating.Soundtrack > animeList[j].Rating.Soundtrack - }) - - saveAs(animeList[:maxPopularAnime], "best anime soundtrack") - - // Done. - color.Green("Finished.") -} - -// Convert to ListOfIDs and save in cache. -func saveAs(list []*arn.Anime, cacheKey string) { - cache := &arn.ListOfIDs{} - - for _, anime := range list { - cache.IDList = append(cache.IDList, anime.ID) - } - - arn.PanicOnError(arn.DB.Set("Cache", cacheKey, cache)) -} diff --git a/jobs/refresh-track-titles/refresh-track-titles.go b/jobs/refresh-track-titles/refresh-track-titles.go deleted file mode 100644 index e6ed3d7f..00000000 --- a/jobs/refresh-track-titles/refresh-track-titles.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -func main() { - color.Yellow("Refreshing track titles") - - // Get a stream of all soundtracks - soundtracks, err := arn.StreamSoundTracks() - - if err != nil { - panic(err) - } - - // Iterate over the stream - for track := range soundtracks { - sync(track) - } - - color.Green("Finished.") -} - -func sync(track *arn.SoundTrack) { - // for _, media := range track.Media { - // media.RefreshMetaData() - // println(media.Service, media.Title) - // } - - // err := track.Save() - - // if err != nil { - // panic(err) - // } -} diff --git a/jobs/sync-characters/sync-characters.go b/jobs/sync-characters/sync-characters.go index 3668d3fa..76ad09a8 100644 --- a/jobs/sync-characters/sync-characters.go +++ b/jobs/sync-characters/sync-characters.go @@ -10,6 +10,7 @@ import ( func main() { color.Yellow("Syncing characters with Kitsu DB") + defer arn.Node.Close() kitsuCharacters := kitsu.StreamCharacters() @@ -23,7 +24,7 @@ func main() { fmt.Printf("%s %s\n", character.ID, character.Name) - arn.PanicOnError(character.Save()) + character.Save() } color.Green("Finished.") diff --git a/jobs/sync-media-relations/sync-media-relations.go b/jobs/sync-media-relations/sync-media-relations.go index 019e5c4f..2a9fca9d 100644 --- a/jobs/sync-media-relations/sync-media-relations.go +++ b/jobs/sync-media-relations/sync-media-relations.go @@ -12,6 +12,7 @@ import ( func main() { color.Yellow("Syncing media relations with Kitsu DB") + defer arn.Node.Close() kitsuMediaRelations := kitsu.StreamMediaRelations() relations := map[string]*arn.AnimeRelations{} @@ -27,15 +28,11 @@ func main() { destinationAnimeID := mediaRelation.Relationships.Destination.Data.ID // Confirm that the anime IDs are valid - exists, _ := arn.DB.Exists("Anime", animeID) - - if !exists { + if !arn.DB.Exists("Anime", animeID) { continue } - exists, _ = arn.DB.Exists("Anime", destinationAnimeID) - - if !exists { + if !arn.DB.Exists("Anime", destinationAnimeID) { continue } @@ -71,11 +68,7 @@ func main() { // Save relations map for _, animeRelations := range relations { - err := animeRelations.Save() - - if err != nil { - color.Red(err.Error()) - } + animeRelations.Save() } color.Green("Finished.") diff --git a/patches/add-balance/add-balance.go b/patches/add-balance/add-balance.go index 8289aab3..dd2326da 100644 --- a/patches/add-balance/add-balance.go +++ b/patches/add-balance/add-balance.go @@ -8,14 +8,10 @@ import ( func main() { color.Yellow("Adding balance to all users") - // Get a stream of all users - allUsers, err := arn.StreamUsers() - arn.PanicOnError(err) - // Iterate over the stream - for user := range allUsers { + for user := range arn.StreamUsers() { user.Balance += 100000 - arn.PanicOnError(user.Save()) + user.Save() } color.Green("Finished.")