From cf00461febfa0da4e3368b5523321c3c8183eef9 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 1 Nov 2017 20:11:05 +0100 Subject: [PATCH] Removed old patches --- patches/add-balance/add-balance.go | 18 --------- patches/add-draft-index/add-draft-index.go | 22 ----------- patches/add-episodes/add-episodes.go | 28 ------------- patches/add-follows/add-follows.go | 39 ------------------- patches/add-item/add-item.go | 5 ++- patches/add-last-seen/add-last-seen.go | 29 -------------- .../add-mal-connections.go | 8 ++-- patches/add-mappings/add-mappings.go | 28 ------------- patches/add-popularity/add-popularity.go | 16 -------- patches/add-push-subs/add-push-subs.go | 39 ------------------- .../clear-anime-ratings.go | 6 ++- patches/clear-sessions/clear-sessions.go | 2 + .../delete-custom-anime.go | 9 +++-- patches/delete-balance/delete-balance.go | 9 ++--- .../delete-invalid-avatars.go | 17 -------- .../delete-private-data.go | 15 +++---- patches/delete-pro/delete-pro.go | 5 ++- patches/fix-airing-dates/fix-airing-dates.go | 6 ++- .../fix-anime-list-item-status.go} | 13 ++----- patches/import-anilist/import-anilist.go | 5 ++- patches/nano-test/main.go | 19 --------- patches/post-texts/post-texts.go | 9 ++--- .../reset-inventories/reset-inventories.go | 13 ++----- patches/thread-posts/thread-posts.go | 10 ++--- .../update-soundtracks/update-soundtracks.go | 11 ------ .../update-user-struct/update-user-struct.go | 22 ----------- patches/user-references/user-references.go | 19 ++++----- .../video-id-to-service-id.go | 38 ------------------ 28 files changed, 57 insertions(+), 403 deletions(-) delete mode 100644 patches/add-balance/add-balance.go delete mode 100644 patches/add-draft-index/add-draft-index.go delete mode 100644 patches/add-episodes/add-episodes.go delete mode 100644 patches/add-follows/add-follows.go delete mode 100644 patches/add-last-seen/add-last-seen.go delete mode 100644 patches/add-mappings/add-mappings.go delete mode 100644 patches/add-popularity/add-popularity.go delete mode 100644 patches/add-push-subs/add-push-subs.go delete mode 100644 patches/delete-invalid-avatars/delete-invalid-avatars.go rename patches/{anime-list-item-status/anime-list-item-status.go => fix-anime-list-item-status/fix-anime-list-item-status.go} (75%) delete mode 100644 patches/nano-test/main.go delete mode 100644 patches/update-soundtracks/update-soundtracks.go delete mode 100644 patches/update-user-struct/update-user-struct.go delete mode 100644 patches/video-id-to-service-id/video-id-to-service-id.go diff --git a/patches/add-balance/add-balance.go b/patches/add-balance/add-balance.go deleted file mode 100644 index dd2326da..00000000 --- a/patches/add-balance/add-balance.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -func main() { - color.Yellow("Adding balance to all users") - - // Iterate over the stream - for user := range arn.StreamUsers() { - user.Balance += 100000 - user.Save() - } - - color.Green("Finished.") -} diff --git a/patches/add-draft-index/add-draft-index.go b/patches/add-draft-index/add-draft-index.go deleted file mode 100644 index 260f4810..00000000 --- a/patches/add-draft-index/add-draft-index.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -func main() { - color.Yellow("Addind draft indices") - - // Iterate over the stream - for user := range arn.MustStreamUsers() { - fmt.Println(user.Nick) - - draftIndex := arn.NewDraftIndex(user.ID) - arn.PanicOnError(draftIndex.Save()) - } - - color.Green("Finished.") -} diff --git a/patches/add-episodes/add-episodes.go b/patches/add-episodes/add-episodes.go deleted file mode 100644 index 111d0644..00000000 --- a/patches/add-episodes/add-episodes.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/animenotifier/arn" -) - -func main() { - count := 0 - - for anime := range arn.MustStreamAnime() { - episodes := anime.Episodes() - - if episodes == nil { - episodes = &arn.AnimeEpisodes{ - AnimeID: anime.ID, - Items: []*arn.AnimeEpisode{}, - } - - if episodes.Save() == nil { - count++ - } - } - } - - fmt.Println("Added empty anime episodes to", count, "anime.") -} diff --git a/patches/add-follows/add-follows.go b/patches/add-follows/add-follows.go deleted file mode 100644 index a30c9a40..00000000 --- a/patches/add-follows/add-follows.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -func main() { - color.Yellow("Adding user follows to users who don't have one") - - // Get a stream of all users - allUsers, err := arn.StreamUsers() - arn.PanicOnError(err) - - // Iterate over the stream - for user := range allUsers { - exists, err := arn.DB.Exists("UserFollows", user.ID) - - if err != nil || exists { - continue - } - - fmt.Println(user.Nick) - - follows := &arn.UserFollows{} - follows.UserID = user.ID - follows.Items = user.Following - - err = arn.DB.Set("UserFollows", follows.UserID, follows) - - if err != nil { - color.Red(err.Error()) - } - } - - color.Green("Finished.") -} diff --git a/patches/add-item/add-item.go b/patches/add-item/add-item.go index d624745b..85ad81d5 100644 --- a/patches/add-item/add-item.go +++ b/patches/add-item/add-item.go @@ -19,6 +19,8 @@ func init() { } func main() { + defer arn.Node.Close() + if nick == "" || itemID == "" { color.Red("Missing parameters") return @@ -38,6 +40,5 @@ func main() { // Add to user inventory inventory := user.Inventory() inventory.AddItem(itemID, uint(quantity)) - err = inventory.Save() - arn.PanicOnError(err) + inventory.Save() } diff --git a/patches/add-last-seen/add-last-seen.go b/patches/add-last-seen/add-last-seen.go deleted file mode 100644 index d2c3f228..00000000 --- a/patches/add-last-seen/add-last-seen.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" -) - -func main() { - // Get a stream of all users - allUsers, err := arn.StreamUsers() - - if err != nil { - panic(err) - } - - // Iterate over the stream - for user := range allUsers { - if user.LastSeen != "" { - continue - } - - user.LastSeen = user.LastLogin - - if user.LastSeen == "" { - user.LastSeen = user.Registered - } - - user.Save() - } -} diff --git a/patches/add-mal-connections/add-mal-connections.go b/patches/add-mal-connections/add-mal-connections.go index b9bf2596..2f3a8057 100644 --- a/patches/add-mal-connections/add-mal-connections.go +++ b/patches/add-mal-connections/add-mal-connections.go @@ -8,7 +8,9 @@ import ( ) func main() { - for anime := range arn.MustStreamAnime() { + defer arn.Node.Close() + + for anime := range arn.StreamAnime() { malID := anime.GetMapping("myanimelist/anime") if malID == "" { @@ -25,11 +27,11 @@ func main() { } // Save - arn.PanicOnError(arn.DB.Set("MyAnimeListToAnime", malID, &arn.MyAnimeListToAnime{ + arn.DB.Set("MyAnimeListToAnime", malID, &arn.MyAnimeListToAnime{ AnimeID: anime.ID, ServiceID: malID, Edited: arn.DateTimeUTC(), EditedBy: "", - })) + }) } } diff --git a/patches/add-mappings/add-mappings.go b/patches/add-mappings/add-mappings.go deleted file mode 100644 index 12c2f541..00000000 --- a/patches/add-mappings/add-mappings.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/animenotifier/arn" -) - -var mappings = map[string]arn.Mapping{ - "13055": arn.Mapping{ - Service: "shoboi/anime", - ServiceID: "4528", - }, -} - -func main() { - for animeID, mapping := range mappings { - anime, err := arn.GetAnime(animeID) - - if err != nil { - panic(err) - } - - fmt.Println(anime.ID, "=", mapping.Service, mapping.ServiceID) - anime.AddMapping(mapping.Service, mapping.ServiceID, "4J6qpK1ve") - anime.Save() - } -} diff --git a/patches/add-popularity/add-popularity.go b/patches/add-popularity/add-popularity.go deleted file mode 100644 index c799eaca..00000000 --- a/patches/add-popularity/add-popularity.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" -) - -func main() { - for anime := range arn.MustStreamAnime() { - if anime.Popularity != nil { - continue - } - - anime.Popularity = &arn.AnimePopularity{} - arn.PanicOnError(anime.Save()) - } -} diff --git a/patches/add-push-subs/add-push-subs.go b/patches/add-push-subs/add-push-subs.go deleted file mode 100644 index 932487a2..00000000 --- a/patches/add-push-subs/add-push-subs.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -func main() { - color.Yellow("Adding push subscriptions to users who don't have one") - - // Get a stream of all users - allUsers, err := arn.StreamUsers() - - if err != nil { - panic(err) - } - - // Iterate over the stream - for user := range allUsers { - exists, err := arn.DB.Exists("PushSubscriptions", user.ID) - - if err == nil && !exists { - fmt.Println(user.Nick) - - err := arn.DB.Set("PushSubscriptions", user.ID, &arn.PushSubscriptions{ - UserID: user.ID, - Items: make([]*arn.PushSubscription, 0), - }) - - if err != nil { - color.Red(err.Error()) - } - } - } - - color.Green("Finished.") -} diff --git a/patches/clear-anime-ratings/clear-anime-ratings.go b/patches/clear-anime-ratings/clear-anime-ratings.go index 359dea2c..c847c56f 100644 --- a/patches/clear-anime-ratings/clear-anime-ratings.go +++ b/patches/clear-anime-ratings/clear-anime-ratings.go @@ -3,8 +3,10 @@ package main import "github.com/animenotifier/arn" func main() { - for anime := range arn.MustStreamAnime() { + defer arn.Node.Close() + + for anime := range arn.StreamAnime() { anime.Rating.Reset() - anime.MustSave() + anime.Save() } } diff --git a/patches/clear-sessions/clear-sessions.go b/patches/clear-sessions/clear-sessions.go index 66324afc..e811932f 100644 --- a/patches/clear-sessions/clear-sessions.go +++ b/patches/clear-sessions/clear-sessions.go @@ -6,6 +6,8 @@ import ( ) func main() { + defer arn.Node.Close() + color.Yellow("Deleting all sessions...") arn.DB.Clear("Session") color.Green("Finished.") diff --git a/patches/delete-anilist-mappings/delete-custom-anime.go b/patches/delete-anilist-mappings/delete-custom-anime.go index 1160d3f8..b9fa6232 100644 --- a/patches/delete-anilist-mappings/delete-custom-anime.go +++ b/patches/delete-anilist-mappings/delete-custom-anime.go @@ -5,11 +5,12 @@ import ( ) func main() { - for anime := range arn.MustStreamAnime() { + defer arn.Node.Close() + + for anime := range arn.StreamAnime() { providerID := anime.GetMapping("anilist/anime") - _, err := arn.DB.Delete("AniListToAnime", providerID) - arn.PanicOnError(err) + arn.DB.Delete("AniListToAnime", providerID) anime.RemoveMapping("anilist/anime", providerID) - arn.PanicOnError(anime.Save()) + anime.Save() } } diff --git a/patches/delete-balance/delete-balance.go b/patches/delete-balance/delete-balance.go index bc329500..0dfa6e0b 100644 --- a/patches/delete-balance/delete-balance.go +++ b/patches/delete-balance/delete-balance.go @@ -23,15 +23,12 @@ func main() { } color.Yellow("Resetting balance of all users to 0") - - // Get a stream of all users - allUsers, err := arn.StreamUsers() - arn.PanicOnError(err) + defer arn.Node.Close() // Iterate over the stream - for user := range allUsers { + for user := range arn.StreamUsers() { user.Balance = 0 - arn.PanicOnError(user.Save()) + user.Save() } color.Green("Finished.") diff --git a/patches/delete-invalid-avatars/delete-invalid-avatars.go b/patches/delete-invalid-avatars/delete-invalid-avatars.go deleted file mode 100644 index 18e7016c..00000000 --- a/patches/delete-invalid-avatars/delete-invalid-avatars.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "strings" - - "github.com/animenotifier/arn" -) - -func main() { - for user := range arn.MustStreamUsers() { - if !strings.HasPrefix(user.Avatar.Extension, ".") { - user.Avatar.Extension = "" - } - - user.Save() - } -} diff --git a/patches/delete-private-data/delete-private-data.go b/patches/delete-private-data/delete-private-data.go index 6b3d4ad2..7520cdf1 100644 --- a/patches/delete-private-data/delete-private-data.go +++ b/patches/delete-private-data/delete-private-data.go @@ -7,20 +7,15 @@ import ( func main() { color.Yellow("Deleting private user data") + defer arn.Node.Close() - // Get a stream of all users - allUsers, err := arn.StreamUsers() - - if err != nil { - panic(err) - } - - arn.DB.DeleteTable("EmailToUser") - arn.DB.DeleteTable("GoogleToUser") + arn.DB.Clear("EmailToUser") + arn.DB.Clear("GoogleToUser") // Iterate over the stream count := 0 - for user := range allUsers { + + for user := range arn.StreamUsers() { count++ println(count, user.Nick) diff --git a/patches/delete-pro/delete-pro.go b/patches/delete-pro/delete-pro.go index 148c7421..1072d682 100644 --- a/patches/delete-pro/delete-pro.go +++ b/patches/delete-pro/delete-pro.go @@ -23,10 +23,11 @@ func main() { } color.Yellow("Deleting all pro subscriptions") + defer arn.Node.Close() - for user := range arn.MustStreamUsers() { + for user := range arn.StreamUsers() { user.ProExpires = "" - arn.PanicOnError(user.Save()) + user.Save() } color.Green("Finished.") diff --git a/patches/fix-airing-dates/fix-airing-dates.go b/patches/fix-airing-dates/fix-airing-dates.go index 9d90af62..87b12547 100644 --- a/patches/fix-airing-dates/fix-airing-dates.go +++ b/patches/fix-airing-dates/fix-airing-dates.go @@ -9,10 +9,12 @@ import ( ) func main() { + defer arn.Node.Close() + now := time.Now() futureThreshold := 8 * 7 * 24 * time.Hour - for anime := range arn.MustStreamAnime() { + for anime := range arn.StreamAnime() { modified := false // Try to find incorrect airing dates @@ -38,7 +40,7 @@ func main() { } if modified == true { - arn.PanicOnError(anime.Episodes().Save()) + anime.Episodes().Save() } } } diff --git a/patches/anime-list-item-status/anime-list-item-status.go b/patches/fix-anime-list-item-status/fix-anime-list-item-status.go similarity index 75% rename from patches/anime-list-item-status/anime-list-item-status.go rename to patches/fix-anime-list-item-status/fix-anime-list-item-status.go index 97233c47..7f9323d8 100644 --- a/patches/anime-list-item-status/anime-list-item-status.go +++ b/patches/fix-anime-list-item-status/fix-anime-list-item-status.go @@ -9,16 +9,10 @@ import ( func main() { color.Yellow("Setting list item status to correct value") - - // Get a stream of all anime lists - allAnimeLists, err := arn.StreamAnimeLists() - - if err != nil { - panic(err) - } + defer arn.Node.Close() // Iterate over the stream - for animeList := range allAnimeLists { + for animeList := range arn.StreamAnimeLists() { fmt.Println(animeList.User().Nick) for _, item := range animeList.Items { @@ -32,8 +26,7 @@ func main() { } } - err := animeList.Save() - arn.PanicOnError(err) + animeList.Save() } color.Green("Finished.") diff --git a/patches/import-anilist/import-anilist.go b/patches/import-anilist/import-anilist.go index 17335d01..1bd427ce 100644 --- a/patches/import-anilist/import-anilist.go +++ b/patches/import-anilist/import-anilist.go @@ -7,6 +7,8 @@ import ( ) func main() { + defer arn.Node.Close() + arn.PanicOnError(anilist.Authorize()) color.Green(anilist.AccessToken) @@ -14,9 +16,8 @@ func main() { arn.PanicOnError(err) count := 0 - stream := anilist.StreamAnime() - for aniListAnime := range stream { + for aniListAnime := range anilist.StreamAnime() { println(aniListAnime.TitleRomaji) anime := arn.FindAniListAnime(aniListAnime, allAnime) diff --git a/patches/nano-test/main.go b/patches/nano-test/main.go deleted file mode 100644 index af91a252..00000000 --- a/patches/nano-test/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" -) - -func main() { - defer arn.Node.Close() - - user, _ := arn.GetUserByNick("Akyoto") - - if user.Language == ":)" { - user.Language = ":(" - } else { - user.Language = ":)" - } - - user.Save() -} diff --git a/patches/post-texts/post-texts.go b/patches/post-texts/post-texts.go index d448616d..4c5fb314 100644 --- a/patches/post-texts/post-texts.go +++ b/patches/post-texts/post-texts.go @@ -7,12 +7,10 @@ import ( ) func main() { - // Get a stream of all posts - allPosts, err := arn.StreamPosts() - arn.PanicOnError(err) + defer arn.Node.Close() // Iterate over the stream - for post := range allPosts { + for post := range arn.StreamPosts() { // Fix text color.Yellow(post.Text) post.Text = autocorrect.FixPostText(post.Text) @@ -24,7 +22,6 @@ func main() { } // Save - err = post.Save() - arn.PanicOnError(err) + post.Save() } } diff --git a/patches/reset-inventories/reset-inventories.go b/patches/reset-inventories/reset-inventories.go index 5e4e8149..413bbb66 100644 --- a/patches/reset-inventories/reset-inventories.go +++ b/patches/reset-inventories/reset-inventories.go @@ -24,21 +24,14 @@ func main() { } color.Yellow("Resetting all inventories") - - // Get a stream of all users - allUsers, err := arn.StreamUsers() - arn.PanicOnError(err) + defer arn.Node.Close() // Iterate over the stream - for user := range allUsers { + for user := range arn.StreamUsers() { fmt.Println(user.Nick) inventory := arn.NewInventory(user.ID) - err = inventory.Save() - - if err != nil { - color.Red(err.Error()) - } + inventory.Save() } color.Green("Finished.") diff --git a/patches/thread-posts/thread-posts.go b/patches/thread-posts/thread-posts.go index c668ab73..166d414b 100644 --- a/patches/thread-posts/thread-posts.go +++ b/patches/thread-posts/thread-posts.go @@ -5,14 +5,13 @@ import ( ) func main() { - // Get a stream of all posts - allPosts, err := arn.StreamPosts() - arn.PanicOnError(err) + defer arn.Node.Close() + // Get a stream of all posts threadToPosts := make(map[string][]string) // Iterate over the stream - for post := range allPosts { + for post := range arn.StreamPosts() { _, found := threadToPosts[post.ThreadID] if !found { @@ -28,7 +27,6 @@ func main() { arn.PanicOnError(err) thread.Posts = posts - err = thread.Save() - arn.PanicOnError(err) + thread.Save() } } diff --git a/patches/update-soundtracks/update-soundtracks.go b/patches/update-soundtracks/update-soundtracks.go deleted file mode 100644 index 833156c2..00000000 --- a/patches/update-soundtracks/update-soundtracks.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "github.com/animenotifier/arn" -) - -func main() { - for track := range arn.MustStreamSoundTracks() { - arn.PanicOnError(track.Save()) - } -} diff --git a/patches/update-user-struct/update-user-struct.go b/patches/update-user-struct/update-user-struct.go deleted file mode 100644 index 512cd1ee..00000000 --- a/patches/update-user-struct/update-user-struct.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "github.com/fatih/color" -) - -func main() { - color.Yellow("Updating user struct") - - // // Iterate over the stream - // for user := range arn.MustStreamUsers() { - // newUser := &arn.UserNew{} - - // copier.Copy(newUser, user) - // newUser.Avatar.Extension = user.Avatar - - // // Save in DB - // arn.PanicOnError(arn.DB.Set("User", user.ID, newUser)) - // } - - color.Green("Finished.") -} diff --git a/patches/user-references/user-references.go b/patches/user-references/user-references.go index c25e37a8..f5aab5f7 100644 --- a/patches/user-references/user-references.go +++ b/patches/user-references/user-references.go @@ -7,22 +7,17 @@ import ( func main() { color.Yellow("Updating user references") + defer arn.Node.Close() - arn.DB.DeleteTable("NickToUser") - arn.DB.DeleteTable("EmailToUser") - arn.DB.DeleteTable("GoogleToUser") - arn.DB.DeleteTable("FacebookToUser") - - // Get a stream of all users - allUsers, err := arn.StreamUsers() - - if err != nil { - panic(err) - } + arn.DB.Clear("NickToUser") + arn.DB.Clear("EmailToUser") + arn.DB.Clear("GoogleToUser") + arn.DB.Clear("FacebookToUser") // Iterate over the stream count := 0 - for user := range allUsers { + + for user := range arn.StreamUsers() { count++ println(count, user.Nick) diff --git a/patches/video-id-to-service-id/video-id-to-service-id.go b/patches/video-id-to-service-id/video-id-to-service-id.go deleted file mode 100644 index d2d7136a..00000000 --- a/patches/video-id-to-service-id/video-id-to-service-id.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -func main() { - -} - -// import ( -// "github.com/animenotifier/arn" -// "github.com/fatih/color" -// ) - -// func main() { -// // Get a stream of all anime -// allAnime, err := arn.AllAnime() - -// if err != nil { -// panic(err) -// } - -// // Iterate over the stream -// for _, anime := range allAnime { -// for _, trailer := range anime.Trailers { -// // trailer.ServiceID = trailer.DeprecatedVideoID -// println(trailer.DeprecatedVideoID) -// trailer.ServiceID = trailer.DeprecatedVideoID -// } - -// if anime.Trailers == nil { -// anime.Trailers = []*arn.ExternalMedia{} -// } - -// err := anime.Save() - -// if err != nil { -// color.Red("Error saving anime: %v", err) -// } -// } -// }