diff --git a/pages/listimport/listimportmyanimelist/myanimelist.go b/pages/listimport/listimportmyanimelist/myanimelist.go index 20050750..7b816e37 100644 --- a/pages/listimport/listimportmyanimelist/myanimelist.go +++ b/pages/listimport/listimportmyanimelist/myanimelist.go @@ -2,6 +2,7 @@ package listimportmyanimelist import ( "net/http" + "strconv" "github.com/aerogo/aero" "github.com/animenotifier/arn" @@ -35,6 +36,49 @@ func Finish(ctx *aero.Context) string { return ctx.Error(http.StatusBadRequest, "Not logged in", nil) } + matches, response := getMatches(ctx) + + if response != "" { + return response + } + + animeList := user.AnimeList() + + for _, match := range matches { + if match.ARNAnime == nil || match.MyAnimeListItem == nil { + continue + } + + rating, _ := strconv.ParseFloat(match.MyAnimeListItem.MyScore, 64) + episodesWatched, _ := strconv.Atoi(match.MyAnimeListItem.MyWatchedEpisodes) + rewatchCount, convErr := strconv.Atoi(match.MyAnimeListItem.MyRewatching) + + if convErr != nil { + rewatchCount = 0 + } + + item := &arn.AnimeListItem{ + AnimeID: match.ARNAnime.ID, + Status: arn.MyAnimeListStatusToARNStatus(match.MyAnimeListItem.MyStatus), + Episodes: episodesWatched, + Notes: "", + Rating: &arn.AnimeRating{ + Overall: rating, + }, + RewatchCount: rewatchCount, + Created: arn.DateTimeUTC(), + Edited: arn.DateTimeUTC(), + } + + animeList.Import(item) + } + + err := animeList.Save() + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Error saving your anime list", err) + } + return ctx.Redirect("/+" + user.Nick + "/animelist") } diff --git a/tests.go b/tests.go index f26ca750..ae7db0ed 100644 --- a/tests.go +++ b/tests.go @@ -174,19 +174,21 @@ var routeTests = map[string][]string{ }, // Disable these tests because they require authorization - "/auth/google": nil, - "/auth/google/callback": nil, - "/auth/facebook": nil, - "/auth/facebook/callback": nil, - "/import": nil, - "/import/anilist/animelist": nil, - "/import/anilist/animelist/finish": nil, - "/anime/:id/edit": nil, - "/new/thread": nil, - "/new/soundtrack": nil, - "/user": nil, - "/settings": nil, - "/extension/embed": nil, + "/auth/google": nil, + "/auth/google/callback": nil, + "/auth/facebook": nil, + "/auth/facebook/callback": nil, + "/import": nil, + "/import/anilist/animelist": nil, + "/import/anilist/animelist/finish": nil, + "/import/myanimelist/animelist": nil, + "/import/myanimelist/animelist/finish": nil, + "/anime/:id/edit": nil, + "/new/thread": nil, + "/new/soundtrack": nil, + "/user": nil, + "/settings": nil, + "/extension/embed": nil, } // API interfaces