Added stuff

This commit is contained in:
David Alasow 2018-11-28 17:00:45 +01:00
parent cb06b74d17
commit a53fff7391

58
main.go
View File

@ -15,7 +15,7 @@ func main() {
r := router.New()
r.GET(`/`, home)
r.GET(`/compare/:user`, compare)
r.Start(`:8080`)
r.Start(`:8070`)
}
type jikanAPIUserList struct {
@ -31,7 +31,8 @@ type jikanAPIUserList struct {
}
type jikanAPIAnime struct {
MalID int `json:"mal_id"`
MeikanID int `json:"meikan_id"`
MyanimelistID int `json:"mal_id"`
Title string `json:"title"`
ImageURL string `json:"image_url"`
Type string `json:"type"`
@ -39,7 +40,25 @@ type jikanAPIAnime struct {
Score int `json:"score"`
WatchedEpisodes int `json:"watched_episodes"`
TotalEpisodes int `json:"total_episodes"`
MeikanID int `json:"meikan_id"`
AiringStatus int `json:"airing_status"`
}
type meikanListItem struct {
Anime meikanAnime `json:"anime"`
State string `json:"state"`
Episode int `json:"episode"`
Rating int `json:"rating"`
Hidden bool `json:"hidden"`
Recommended bool `json:"recommend"`
}
type meikanAnime struct {
ID int `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Episodes int `json:"episodes"`
State string `json:"state"`
Rating string `json:"rating"`
}
type meikanAPIIDs struct {
@ -63,27 +82,46 @@ func compare(c *router.Context) error {
//https://api.jikan.moe/v3/user/nekomata1037/animelist/all
//https://api.meikan.moe/v1/ids/anime
jikanList := jikanAPIGetUserAnimelist(user)
var anime []meikanListItem
//fmt.Println(result)
IDs := meikanAPIGetIDs()
for i := 0; i < len(jikanList.Anime); i++ {
//fmt.Println(result.Anime[i].Title)
for d := 0; d < len(IDs); d++ {
if jikanList.Anime[i].MalID == IDs[d].MyanimelistID {
if jikanList.Anime[i].MyanimelistID == IDs[d].MyanimelistID {
jikanList.Anime[i].MeikanID = IDs[d].MeikanID
}
}
if jikanList.Anime[i].WatchingStatus == 1 {
jikanList.Watching++
} else if jikanList.Anime[i].WatchingStatus == 2 {
temp := meikanListItem{Anime: meikanAnime{ID: jikanList.Anime[i].MeikanID,
Title: jikanList.Anime[i].Title,
Type: jikanList.Anime[i].Type,
Episodes: jikanList.Anime[i].TotalEpisodes},
Episode: jikanList.Anime[i].WatchedEpisodes,
Rating: jikanList.Anime[i].Score}
switch jikanList.Anime[i].WatchingStatus {
case 1:
jikanList.Completed++
} else if jikanList.Anime[i].WatchingStatus == 3 {
temp.State = "Watching"
case 2:
jikanList.Completed++
temp.State = "Finished"
case 3:
jikanList.OnHold++
} else if jikanList.Anime[i].WatchingStatus == 4 {
temp.State = "On Hold"
case 4:
jikanList.Dropped++
} else if jikanList.Anime[i].WatchingStatus == 6 {
temp.State = "Dropped"
case 6:
jikanList.PlanToWatch++
temp.State = "Plan to watch"
}
switch jikanList.Anime[i].AiringStatus {
case 2:
temp.Anime.State = "Finished"
}
anime = append(anime, temp)
}
//fmt.Println(anime)
//resJSON, err := json.MarshalIndent(result, "", "\t")
//check(err)
//jsonfile := []byte(resJSON)