From 2010e9ed6872a10abe25fdc898a5a3b02a992222 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 3 Apr 2018 22:53:53 +0200 Subject: [PATCH] Improved import --- pages/home/home.go | 11 +++++++- pages/listimport/listimportanilist/anilist.go | 10 ++++++- pages/listimport/listimportkitsu/kitsu.go | 10 ++++++- .../listimportmyanimelist/myanimelist.go | 10 ++++++- .../import-mal-anime-data.go | 28 ++++++++++++------- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/pages/home/home.go b/pages/home/home.go index b10f2554..91cd137c 100644 --- a/pages/home/home.go +++ b/pages/home/home.go @@ -1,6 +1,8 @@ package home import ( + "strings" + "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/pages/frontpage" "github.com/animenotifier/notify.moe/utils" @@ -14,5 +16,12 @@ func Get(ctx *aero.Context) string { return frontpage.Get(ctx) } - return ctx.Redirect("/+" + user.Nick + "/animelist/watching") + // Redirect + prefix := "/" + + if strings.HasPrefix(ctx.URI(), "/_") { + prefix = "/_/" + } + + return ctx.Redirect(prefix + "+" + user.Nick + "/animelist/watching") } diff --git a/pages/listimport/listimportanilist/anilist.go b/pages/listimport/listimportanilist/anilist.go index 322bf282..adcc7cd7 100644 --- a/pages/listimport/listimportanilist/anilist.go +++ b/pages/listimport/listimportanilist/anilist.go @@ -2,6 +2,7 @@ package listimportanilist import ( "net/http" + "strings" "github.com/aerogo/aero" "github.com/animenotifier/anilist" @@ -66,7 +67,14 @@ func Finish(ctx *aero.Context) string { animeList.Save() - return ctx.Redirect("/+" + user.Nick + "/animelist/watching") + // Redirect + prefix := "/" + + if strings.HasPrefix(ctx.URI(), "/_") { + prefix = "/_/" + } + + return ctx.Redirect(prefix + "+" + user.Nick + "/animelist/watching") } // getMatches finds and returns all matches for the logged in user. diff --git a/pages/listimport/listimportkitsu/kitsu.go b/pages/listimport/listimportkitsu/kitsu.go index 4671013f..3a0238f7 100644 --- a/pages/listimport/listimportkitsu/kitsu.go +++ b/pages/listimport/listimportkitsu/kitsu.go @@ -2,6 +2,7 @@ package listimportkitsu import ( "net/http" + "strings" "github.com/aerogo/aero" "github.com/animenotifier/arn" @@ -79,7 +80,14 @@ func Finish(ctx *aero.Context) string { animeList.Save() - return ctx.Redirect("/+" + user.Nick + "/animelist/watching") + // Redirect + prefix := "/" + + if strings.HasPrefix(ctx.URI(), "/_") { + prefix = "/_/" + } + + return ctx.Redirect(prefix + "+" + user.Nick + "/animelist/watching") } // getMatches finds and returns all matches for the logged in user. diff --git a/pages/listimport/listimportmyanimelist/myanimelist.go b/pages/listimport/listimportmyanimelist/myanimelist.go index d8a5cf1a..19ab9792 100644 --- a/pages/listimport/listimportmyanimelist/myanimelist.go +++ b/pages/listimport/listimportmyanimelist/myanimelist.go @@ -3,6 +3,7 @@ package listimportmyanimelist import ( "net/http" "strconv" + "strings" "github.com/aerogo/aero" "github.com/animenotifier/arn" @@ -75,7 +76,14 @@ func Finish(ctx *aero.Context) string { animeList.Save() - return ctx.Redirect("/+" + user.Nick + "/animelist/watching") + // Redirect + prefix := "/" + + if strings.HasPrefix(ctx.URI(), "/_") { + prefix = "/_/" + } + + return ctx.Redirect(prefix + "+" + user.Nick + "/animelist/watching") } // getMatches finds and returns all matches for the logged in user. diff --git a/patches/import-mal-anime-data/import-mal-anime-data.go b/patches/import-mal-anime-data/import-mal-anime-data.go index 383fbfef..34170ab2 100644 --- a/patches/import-mal-anime-data/import-mal-anime-data.go +++ b/patches/import-mal-anime-data/import-mal-anime-data.go @@ -21,7 +21,7 @@ func main() { continue } - fmt.Println(anime.Title.Canonical, malID) + fmt.Printf("%s %s\n", color.CyanString(anime.Title.Canonical), malID) sync(anime, malID) } @@ -38,37 +38,45 @@ func sync(anime *arn.Anime, malID string) { malAnime := obj.(*mal.Anime) - if len(anime.Genres) == 0 { + if len(anime.Genres) == 0 && len(malAnime.Genres) > 0 { + fmt.Println("Genres:", malAnime.Genres) anime.Genres = malAnime.Genres } - if anime.EpisodeCount == 0 { + if anime.EpisodeCount == 0 && malAnime.EpisodeCount != 0 { + fmt.Println("EpisodeCount:", malAnime.EpisodeCount) anime.EpisodeCount = malAnime.EpisodeCount } - if anime.EpisodeLength == 0 { + if anime.EpisodeLength == 0 && malAnime.EpisodeLength != 0 { + fmt.Println("EpisodeLength:", malAnime.EpisodeLength) anime.EpisodeLength = malAnime.EpisodeLength } - if anime.StartDate == "" { + if anime.StartDate == "" && malAnime.StartDate != "" { + fmt.Println("StartDate:", malAnime.StartDate) anime.StartDate = malAnime.StartDate } - if anime.EndDate == "" { + if anime.EndDate == "" && malAnime.EndDate != "" { + fmt.Println("EndDate:", malAnime.EndDate) anime.EndDate = malAnime.EndDate } - if anime.Source == "" { + if anime.Source == "" && malAnime.Source != "" { + fmt.Println("Source:", malAnime.Source) anime.Source = malAnime.Source } - if anime.Title.Japanese == "" { + if anime.Title.Japanese == "" && malAnime.JapaneseTitle != "" { + fmt.Println("JapaneseTitle:", malAnime.JapaneseTitle) anime.Title.Japanese = malAnime.JapaneseTitle } - if anime.Title.English == "" { + if anime.Title.English == "" && malAnime.EnglishTitle != "" { + fmt.Println("EnglishTitle:", malAnime.EnglishTitle) anime.Title.English = malAnime.EnglishTitle } - anime.Save() + // anime.Save() }