You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
3.9 KiB
152 lines
3.9 KiB
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"jschan/app"
|
|
"jschan/app/models"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
|
|
jschanClient := jschan.NewClient("https://fatchan.org")
|
|
ctx := context.Background()
|
|
|
|
loginOptions := &jschan.PostLoginOptions{
|
|
Username: "",
|
|
Password: "",
|
|
Twofactor: "",
|
|
}
|
|
err := jschanClient.Login(ctx, loginOptions)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
if jschanClient.SessionCookie != "" {
|
|
fmt.Printf("Logged in as user %s\n", loginOptions.Username)
|
|
if _, err := jschanClient.GetCSRFToken(ctx); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
|
|
overboardOptions := &jschan.GetOverboardOptions{
|
|
IncludeDefault: true,
|
|
}
|
|
res, err := jschanClient.GetOverboardCatalog(ctx, overboardOptions)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched overboard catalog with %d threads\n", len(res.Threads))
|
|
|
|
getCatalogOptions := &jschan.GetCatalogOptions{
|
|
Board: "t",
|
|
}
|
|
res2, err2 := jschanClient.GetCatalog(ctx, getCatalogOptions)
|
|
if err2 != nil {
|
|
fmt.Println(err2)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched board %s catalog with %d threads\n", getCatalogOptions.Board, len(res2))
|
|
|
|
getThreadOptions := &jschan.GetThreadOptions{
|
|
Board: "t",
|
|
ThreadId: 1392,
|
|
}
|
|
res3, err3 := jschanClient.GetThread(ctx, getThreadOptions)
|
|
if err3 != nil {
|
|
fmt.Println(err3)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ thread %d with %d replies\n", getThreadOptions.Board, getThreadOptions.ThreadId, len(res3.Replies))
|
|
|
|
getLogsListOptions := &jschan.GetLogsListOptions{
|
|
Board: "t",
|
|
}
|
|
res4, err4 := jschanClient.GetLogsList(ctx, getLogsListOptions)
|
|
if err4 != nil {
|
|
fmt.Println(err4)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ logs with %d entries\n", getLogsListOptions.Board, len(res4))
|
|
|
|
getLogsOptions := &jschan.GetLogsOptions{
|
|
Board: "t",
|
|
Date: models.LogDate{
|
|
Year: 2022,
|
|
Month: 11,
|
|
Day: 02,
|
|
},
|
|
}
|
|
res5, err5 := jschanClient.GetLogs(ctx, getLogsOptions)
|
|
if err5 != nil {
|
|
fmt.Println(err5)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ logs for date %s with %d entries\n", getLogsOptions.Board, getLogsOptions.Date.String(), len(res5))
|
|
|
|
getSettingsOptions := &jschan.GetSettingsOptions{
|
|
Board: "t",
|
|
}
|
|
res6, err6 := jschanClient.GetSettings(ctx, getSettingsOptions)
|
|
if err6 != nil {
|
|
fmt.Println(err6)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ settings. Custompages are: [\"%s\"]\n", getLogsOptions.Board, strings.Join(res6.CustomPages, `", "`))
|
|
|
|
getCustomPageOptions := &jschan.GetCustomPageOptions{
|
|
Board: "t",
|
|
CustomPage: res6.CustomPages[0],
|
|
}
|
|
res7, err7 := jschanClient.GetCustomPage(ctx, getCustomPageOptions)
|
|
if err7 != nil {
|
|
fmt.Println(err7)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ custompage \"%s\" published on: %s\n", getCustomPageOptions.Board, getCustomPageOptions.CustomPage, res7.Date.String())
|
|
|
|
getBannersOptions := &jschan.GetBannersOptions{
|
|
Board: "t",
|
|
}
|
|
res8, err8 := jschanClient.GetBanners(ctx, getBannersOptions)
|
|
if err8 != nil {
|
|
fmt.Println(err8)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched banners for /%s/: [\"%s\"]\n", getCustomPageOptions.Board, strings.Join(res8, `", "`))
|
|
|
|
res9, err9 := jschanClient.GetWebring(ctx)
|
|
if err9 != nil {
|
|
fmt.Println(err9)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched webring, following: [\"%s\"]\n", strings.Join(res9.Following, `", "`))
|
|
|
|
// makePostOptions := &jschan.MakePostOptions{
|
|
// Board: "test",
|
|
// Thread: 277,
|
|
// Name: "Test",
|
|
// Message: ">test",
|
|
// Email: "sage",
|
|
// PostPassword: "123",
|
|
// Files: []string{"./image.png", "./image.png"},
|
|
// }
|
|
// err10 := jschanClient.MakePost(ctx, makePostOptions)
|
|
// if err10 != nil {
|
|
// fmt.Println(err10)
|
|
// return
|
|
// }
|
|
|
|
getManageRecentOptions := &jschan.GetManageRecentOptions{
|
|
Board: "test",
|
|
}
|
|
res11, err11 := jschanClient.GetManageRecent(ctx, getManageRecentOptions)
|
|
if err11 != nil {
|
|
fmt.Println(err11)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched %d manage recent posts for /%s/\n", len(res11), getManageRecentOptions.Board)
|
|
|
|
return
|
|
}
|
|
|