Finished MAL import

This commit is contained in:
Eduard Urbach 2017-07-08 02:41:13 +02:00
parent 2edfd91338
commit 0a51b64e88
2 changed files with 59 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package listimportmyanimelist
import ( import (
"net/http" "net/http"
"strconv"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
@ -35,6 +36,49 @@ func Finish(ctx *aero.Context) string {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil) 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") return ctx.Redirect("/+" + user.Nick + "/animelist")
} }

View File

@ -174,19 +174,21 @@ var routeTests = map[string][]string{
}, },
// Disable these tests because they require authorization // Disable these tests because they require authorization
"/auth/google": nil, "/auth/google": nil,
"/auth/google/callback": nil, "/auth/google/callback": nil,
"/auth/facebook": nil, "/auth/facebook": nil,
"/auth/facebook/callback": nil, "/auth/facebook/callback": nil,
"/import": nil, "/import": nil,
"/import/anilist/animelist": nil, "/import/anilist/animelist": nil,
"/import/anilist/animelist/finish": nil, "/import/anilist/animelist/finish": nil,
"/anime/:id/edit": nil, "/import/myanimelist/animelist": nil,
"/new/thread": nil, "/import/myanimelist/animelist/finish": nil,
"/new/soundtrack": nil, "/anime/:id/edit": nil,
"/user": nil, "/new/thread": nil,
"/settings": nil, "/new/soundtrack": nil,
"/extension/embed": nil, "/user": nil,
"/settings": nil,
"/extension/embed": nil,
} }
// API interfaces // API interfaces