refactor: basic implementation of favorites
Signed-off-by: soxx <soxx@fenpa.ws>
This commit is contained in:
parent
be44a669d9
commit
322bb41a97
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -10,44 +11,50 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
client := e621.NewClient(os.Getenv("API_USER"), os.Getenv("API_KEY"))
|
client := e621.NewClient(os.Getenv("API_USER"), os.Getenv("API_KEY"))
|
||||||
{
|
{
|
||||||
favorites, err := client.GetFavoritesForUser("selloo")
|
username := "selloo"
|
||||||
|
|
||||||
|
favoritesBuilder := client.NewFavoritesBuilder().FromUsername(username)
|
||||||
|
posts, err := favoritesBuilder.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
posts, err := favorites.Execute()
|
log.Printf("URL of favorite post 0 for user with name %s is: %s", username, posts[0].File.URL)
|
||||||
if err != nil {
|
|
||||||
log.Panic(err)
|
|
||||||
}
|
|
||||||
log.Printf("URL of favorite post 0 is: %s", posts[0].File.URL)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
favoritesBuilder, _ := client.GetFavoritesForUser("selloo")
|
userID := 123456
|
||||||
favorites, err := client.GetNFavoritesForUser(10, favoritesBuilder)
|
|
||||||
|
favoritesBuilder := client.NewFavoritesBuilder().FromUserID(model.UserID(userID))
|
||||||
|
posts, err := favoritesBuilder.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
log.Printf("URL of favorite post 0 for user with id %d is: %s", userID, posts[0].File.URL)
|
||||||
log.Println(len(favorites))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
favoritesBuilder, _ := client.GetFavoritesForUser("selloo")
|
username := "selloo"
|
||||||
favorites, err := client.GetAllFavoritesForUser(favoritesBuilder)
|
tags := []string{"fennec", "male", "solo"}
|
||||||
|
|
||||||
|
favoritesBuilder := client.NewFavoritesBuilder().FromUsername(username).WithTags(tags)
|
||||||
|
posts, err := favoritesBuilder.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
log.Println(len(favorites))
|
log.Printf("Found %d favorites in %s users favorites", len(posts), username)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
favoritesWithTags := client.GetFavoritesForUserWithTags("selloo", "fennec male solo")
|
userID := 123456
|
||||||
posts, err := favoritesWithTags.Execute()
|
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 {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
log.Printf("URL of favorite post 0 with tags is: %s", posts[0].File.URL)
|
log.Printf("returning %d posts with tags %s for user with id %d", len(posts), tags, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,8 @@ func (g getFavorites) Execute() ([]model.Post, error) {
|
|||||||
|
|
||||||
if g.tags != "" {
|
if g.tags != "" {
|
||||||
// TODO: implement with tags (channels)
|
// TODO: implement with tags (channels)
|
||||||
|
} else {
|
||||||
|
return basicFavoritesBuilder.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
return userFavorites, err
|
return userFavorites, err
|
||||||
|
@ -1,23 +1,12 @@
|
|||||||
package e621
|
package e621
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"compress/gzip"
|
|
||||||
"encoding/csv"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
|
||||||
"github.com/gocarina/gocsv"
|
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
"log"
|
|
||||||
"math"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is the main client for interacting with the e621 API.
|
// Client is the main client for interacting with the e621 API.
|
||||||
@ -40,7 +29,11 @@ func NewClient(username string, apiKey string) Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserBuilder returns a UserBuilder instance for creating and executing requests to retrieve user information from the e621 API.
|
func (c *Client) NewFavoritesBuilder() builder.FavoritesBuilder {
|
||||||
|
return builder.NewGetFavoritesBuilder(c.RequestContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*// GetUserBuilder returns a UserBuilder instance for creating and executing requests to retrieve user information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.UserBuilder: An instance of the UserBuilder.
|
// - builder.UserBuilder: An instance of the UserBuilder.
|
||||||
@ -376,3 +369,4 @@ func (c *Client) GetLatestPostsDBExportDataAsStruct() ([]*model.Post, error) {
|
|||||||
|
|
||||||
return post, nil
|
return post, nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
Reference in New Issue
Block a user