Finished MAL import
This commit is contained in:
parent
2edfd91338
commit
0a51b64e88
@ -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")
|
||||
}
|
||||
|
||||
|
2
tests.go
2
tests.go
@ -181,6 +181,8 @@ var routeTests = map[string][]string{
|
||||
"/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,
|
||||
|
Loading…
Reference in New Issue
Block a user