This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/e621/favorite.go
2023-06-17 20:51:04 +02:00

37 lines
831 B
Go

package e621
import (
"e621_to_neo4j/e621/models"
"fmt"
"log"
"time"
)
// GetFavorites retrieves all favorites from the e621 API.
func (c *Client) GetFavorites(user models.E621User) ([]models.Post, error) {
time.Sleep(1 * time.Second)
var page int64
var allFavorites []models.Post
var URIPath string
for {
URIPath = fmt.Sprintf("favorites.json?user_id=%d&page=%d", user.ID, page)
favorite, err := ExecuteGetAPIRequest[models.APIe621Post](c, URIPath)
if err != nil {
log.Printf(err.Error())
}
// Append the fetched posts to the result slice
allFavorites = append(allFavorites, favorite.Posts...)
// If no more posts are returned, return the accumulated favorites
if len(favorite.Posts) == 0 {
return allFavorites, nil
}
// Update the last post ID for the next page request
page += 1
}
}