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/midlevel/dbexport.go
soxx be44a669d9 refactor: start rework of the high level API
Signed-off-by: soxx <soxx@fenpa.ws>
2023-11-27 08:12:58 +01:00

56 lines
1.3 KiB
Go

package main
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"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.Println("Getting a list of DB Exports: ")
getDBExportList := basic.NewGetDBExportListBuilder(requestContext)
dbExportFiles, err := getDBExportList.Execute()
if err != nil {
panic(err)
}
log.Printf("%d files found", len(dbExportFiles))
for _, v := range dbExportFiles {
log.Printf("File found: %s", v)
}
log.Println(dbExportFiles)
exportFileName := dbExportFiles[0]
log.Println("Downloading DB export")
log.Printf("File to download: %s", exportFileName)
getDBExportFile := basic.NewGetDBExportFileBuilder(requestContext)
rawFile, err := getDBExportFile.SetFile(exportFileName).Execute()
file, err := os.Create(exportFileName)
if err != nil {
panic(err)
}
defer file.Close()
err = os.WriteFile(exportFileName, rawFile, 0644)
if err != nil {
panic(err)
}
log.Printf("File %s downloaded", exportFileName)
}