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/example/highlevel/favorites.go
soxx 322bb41a97 refactor: basic implementation of favorites
Signed-off-by: soxx <soxx@fenpa.ws>
2023-11-27 22:37:36 +01:00

61 lines
1.5 KiB
Go

package main
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log"
"os"
)
func main() {
client := e621.NewClient(os.Getenv("API_USER"), os.Getenv("API_KEY"))
{
username := "selloo"
favoritesBuilder := client.NewFavoritesBuilder().FromUsername(username)
posts, err := favoritesBuilder.Execute()
if err != nil {
log.Panic(err)
}
log.Printf("URL of favorite post 0 for user with name %s is: %s", username, posts[0].File.URL)
}
{
userID := 123456
favoritesBuilder := client.NewFavoritesBuilder().FromUserID(model.UserID(userID))
posts, err := favoritesBuilder.Execute()
if err != nil {
log.Panic(err)
}
log.Printf("URL of favorite post 0 for user with id %d is: %s", userID, posts[0].File.URL)
}
{
username := "selloo"
tags := []string{"fennec", "male", "solo"}
favoritesBuilder := client.NewFavoritesBuilder().FromUsername(username).WithTags(tags)
posts, err := favoritesBuilder.Execute()
if err != nil {
log.Panic(err)
}
log.Printf("Found %d favorites in %s users favorites", len(posts), username)
}
{
userID := 123456
tags := []string{"fennec", "male", "solo"}
limit := 5
favoritesBuilder := client.NewFavoritesBuilder().FromUserID(model.UserID(userID)).WithTags(tags).Limit(limit)
posts, err := favoritesBuilder.Execute()
if err != nil {
log.Panic(err)
}
log.Printf("returning %d posts with tags %s for user with id %d", len(posts), tags, userID)
}
}