69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/builder"
|
||
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
|
||
|
_ "github.com/joho/godotenv/autoload"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
// Define the request context with essential information.
|
||
|
requestContext := model.RequestContext{
|
||
|
Client: http.Client{},
|
||
|
Host: "https://e621.net",
|
||
|
UserAgent: "Go-e621-SDK (@username)",
|
||
|
Username: os.Getenv("API_USER"), // Replace with your username
|
||
|
APIKey: os.Getenv("API_KEY"), // Replace with your API key
|
||
|
}
|
||
|
|
||
|
// Log: Getting a single post.
|
||
|
log.Println("Getting single post: ")
|
||
|
|
||
|
// Specify the post ID for retrieval.
|
||
|
postID := 4353480 // Replace with the desired post's ID.
|
||
|
|
||
|
// Call the GetPost function to retrieve the specified post.
|
||
|
getPost := builder.NewGetPostBuilder(requestContext)
|
||
|
post, err := getPost.SetPostID(postID).Execute()
|
||
|
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
} else {
|
||
|
// Log the URL of the retrieved post.
|
||
|
log.Println(post.File.URL)
|
||
|
}
|
||
|
log.Println("----------")
|
||
|
|
||
|
// Log: Getting a list of posts.
|
||
|
log.Println("Getting a list of posts: ")
|
||
|
|
||
|
// Call the GetPosts function to retrieve a list of posts based on the query parameters.
|
||
|
getPosts := builder.NewGetPostsBuilder(requestContext)
|
||
|
posts, err := getPosts.SetLimit(5).Execute()
|
||
|
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
} else {
|
||
|
// Log the number of posts retrieved.
|
||
|
log.Println(len(posts))
|
||
|
}
|
||
|
log.Println("----------")
|
||
|
|
||
|
// Log: Getting a list of posts with tags.
|
||
|
log.Println("Getting a list of posts: ")
|
||
|
|
||
|
// Call the GetPosts function to retrieve a list of posts based on the query parameters.
|
||
|
posts, err = getPosts.SetLimit(5).Tags("fennec").Execute()
|
||
|
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
} else {
|
||
|
// Log the number of posts retrieved.
|
||
|
log.Println(len(posts))
|
||
|
}
|
||
|
log.Println("----------")
|
||
|
}
|