по мелочи

This commit is contained in:
lost+skunk 2024-06-30 14:39:11 +03:00
parent efa4b86a67
commit 949bef2c5d
3 changed files with 36 additions and 33 deletions

View File

@ -1,6 +1,6 @@
# Devianter # Devianter
[![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page) [![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page) [![Go Reference](https://pkg.go.dev/badge/git.macaw.me/skunky/devianter.svg)](https://pkg.go.dev/git.macaw.me/skunky/devianter) [![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
A DeviantART API library for Go. A DeviantART API library for Go.

View File

@ -2,17 +2,11 @@ package devianter
import ( import (
"encoding/json" "encoding/json"
"net/url"
"strconv" "strconv"
"strings"
) )
type Comments struct { type Thread struct {
Cursor string
PrevOffset int
HasMore, HasLess bool
Total int
Thread []struct {
Replies, Likes int Replies, Likes int
ID int `json:"commentId"` ID int `json:"commentId"`
Parent int `json:"parentId"` Parent int `json:"parentId"`
@ -29,21 +23,24 @@ type Comments struct {
Username string Username string
Banned bool `json:"isBanned"` Banned bool `json:"isBanned"`
} }
}
} }
// функция для обработки комментариев поста, пользователя, группы и многого другого type Comments struct {
func CommentsFunc( Cursor string
postid string, PrevOffset int
cursor string, HasMore, HasLess bool
page int,
typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя Total int
) (cmmts Comments) { Thread []Thread
}
// 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
func CommentsFunc(postid string, cursor string, page int, typ int) (cmmts Comments) {
for x := 0; x <= page; x++ { for x := 0; x <= page; x++ {
ujson( ujson(
"dashared/comments/thread?typeid="+strconv.Itoa(typ)+ "dashared/comments/thread?typeid="+strconv.Itoa(typ)+
"&itemid="+postid+"&maxdepth=1000&order=newest"+ "&itemid="+postid+"&maxdepth=1000&order=newest"+
"&limit=50&cursor="+strings.ReplaceAll(cursor, "+", `%2B`), "&limit=50&cursor="+url.QueryEscape(cursor),
&cmmts, &cmmts,
) )

10
misc.go
View File

@ -7,6 +7,7 @@ import (
"log" "log"
"math" "math"
"net/http" "net/http"
u "net/url"
"strconv" "strconv"
"strings" "strings"
) )
@ -134,7 +135,8 @@ type Search struct {
Total int `json:"estTotal"` Total int `json:"estTotal"`
Pages int // only for 'a' and 'g' scope. Pages int // only for 'a' and 'g' scope.
HasMore bool HasMore bool
Results []Deviation `json:"deviations,results"` Results []Deviation `json:"deviations"`
ResultsGalleryTemp []Deviation `json:"results"`
} }
func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, e error) { func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, e error) {
@ -162,7 +164,7 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search,
log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.") log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.")
} }
url.WriteString(query) url.WriteString(u.QueryEscape(query))
if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код
url.WriteString("&page=") url.WriteString("&page=")
} else { // иначе вместо страницы будет оффсет и страница умножится на 50 } else { // иначе вместо страницы будет оффсет и страница умножится на 50
@ -173,6 +175,10 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search,
ujson(url.String(), &ss) ujson(url.String(), &ss)
if scope == 'g' {
ss.Results = ss.ResultsGalleryTemp
}
// расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум
totalfloat := int(math.Round(float64(ss.Total / 25))) totalfloat := int(math.Round(float64(ss.Total / 25)))
for x := 0; x < totalfloat; x++ { for x := 0; x < totalfloat; x++ {