User implementation and particaly groups

This commit is contained in:
lost+skunk 2024-06-05 14:32:40 +03:00
parent 66ab740d7f
commit 9b85088665
7 changed files with 152 additions and 61 deletions

View File

@ -13,24 +13,21 @@ type comments struct {
Total int Total int
Thread []struct { Thread []struct {
CommentId, ParentId, Replies, Likes int Replies, Likes int
Posted time ID int `json:"commentId"`
IsAuthorHighlited bool Parent int `json:"ParrentId"`
Posted time
Author bool `json:"isAuthorHighlited"`
Desctiption string Desctiption string
Comment string
// упрощение структуры с комментами TextContent text
Comment string
TextContent struct {
Html struct {
Markup string
}
}
User struct { User struct {
Username string Username string
IsBanned bool Banned bool `json:"isBanned"`
} }
} }
} }

View File

@ -21,10 +21,14 @@ func (t *time) UnmarshalJSON(b []byte) (err error) {
// самая главная структура для поста // самая главная структура для поста
type deviantion struct { type deviantion struct {
Title, Url, License string Title, Url, License string
PublishedTime time PublishedTime time
IsMature, IsAiGenerated, IsDailyDeviation bool
Author struct { NSFW bool `json:"isMature"`
AI bool `json:"isAiGenerated"`
DD bool `json:"isDailyDeviation"`
Author struct {
Username string Username string
} }
Stats struct { Stats struct {
@ -54,11 +58,13 @@ type media struct {
} }
type text struct { type text struct {
Html struct { Excerpt string
Html struct {
Markup, Type string Markup, Type string
} }
} }
// структура поста
type Deviantion struct { type Deviantion struct {
Deviation deviantion Deviation deviantion
Comments struct { Comments struct {
@ -73,7 +79,6 @@ type Deviantion struct {
} }
IMG, Desctiption string IMG, Desctiption string
Recomendations []deviantion
} }
// для работы функции нужно ID поста и имя пользователя. // для работы функции нужно ID поста и имя пользователя.
@ -98,7 +103,7 @@ func Deviation(id string, user string) Deviantion {
// базовая обработка описания // базовая обработка описания
txt := st.Deviation.TextContent.Html.Markup txt := st.Deviation.TextContent.Html.Markup
if len(txt) > 0 && txt[0:1] == "{" { if len(txt) > 0 && txt[1] == 125 {
var description struct { var description struct {
Blocks []struct { Blocks []struct {
Text string Text string

View File

@ -1,25 +0,0 @@
package main
import (
"git.macaw.me/skunky/devianter"
)
func main() {
id := "973578309"
d := devianter.Deviation(id, "Thrumyeye")
println("Post Name:", d.Deviation.Title, "\nIMG url:", d.IMG)
c := devianter.Comments(id, "", 0, 1)
println("\n\nPost Comments:", c.Total)
for _, a := range c.Thread {
if a.User.IsBanned {
a.User.Username += " [v bane]"
}
println(a.User.Username+":", a.Comment)
}
search := devianter.Search("skunk", "2", 'a')
println(search.Total, search.Pages)
}

View File

@ -2,3 +2,5 @@
- emojis - emojis
- deviantions - deviantions
- comments - comments
- search (including gallery search)
- users (with gallery)

49
misc.go
View File

@ -3,11 +3,11 @@ package devianter
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"log" "log"
"math" "math"
"net/http" "net/http"
"strconv"
"strings" "strings"
) )
@ -117,27 +117,44 @@ func AEmedia(name string, t rune) (string, error) {
/* SEARCH */ /* SEARCH */
type search struct { type search struct {
Total int `json:"estTotal"` Total int `json:"estTotal"`
Pages int // only for 'a' scope. Pages int // only for 'a' and 'g' scope.
Deviations []deviantion Results []deviantion `json:"deviations,results"`
} }
func Search(query, page string, scope rune) (ss search) { func Search(query string, page int, scope rune, user ...string) (ss search, e error) {
var url strings.Builder var url strings.Builder
e = nil
// о5 построение ссылок. // о5 построение ссылок.
switch scope { switch scope {
case 'a': case 'a': // поиск артов по названию
url.WriteString("dabrowse/search/all?q=") url.WriteString("dabrowse/search/all?q=")
case 't': case 't': // поиск артов по тегам
url.WriteString("dabrowse/networkbar/tag/deviations?tag=") url.WriteString("dabrowse/networkbar/tag/deviations?tag=")
case 'g': // поиск артов пользователя или группы
if user != nil {
url.WriteString("dashared/gallection/search?username=")
for _, a := range user {
url.WriteString(a)
}
url.WriteString("&type=gallery&order=most-recent&init=true&limit=50&q=")
} else {
e = errors.New("Missing username (last argument)")
return
}
default: default:
log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag.") log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.")
} }
url.WriteString(query) url.WriteString(query)
url.WriteString("&page=") if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код
url.WriteString(page) url.WriteString("&page=")
} else { // иначе вместо страницы будет оффсет и страница умножится на 50
url.WriteString("&offset=")
page = 50 * page
}
url.WriteString(strconv.Itoa(page))
ujson(url.String(), &ss) ujson(url.String(), &ss)
@ -184,10 +201,14 @@ func puppy(data string) (string, error) {
} }
} }
body := request( var url strings.Builder
fmt.Sprintf("https://www.deviantart.com/_puppy/%s&csrf_token=%s&da_minor_version=20230710", data, token), url.WriteString("https://www.deviantart.com/_puppy/")
cookie, url.WriteString(data)
) url.WriteString("&csrf_token=")
url.WriteString(token)
url.WriteString("&da_minor_version=20230710")
body := request(url.String(), cookie)
// если код ответа не 200, возвращается ошибка // если код ответа не 200, возвращается ошибка
if body.Status != 200 { if body.Status != 200 {

View File

@ -1,3 +1,2 @@
- ~~users~~ - groups
- ~~groups~~ - images in comments
- ~~images in comments~~

92
user-group.go Normal file
View File

@ -0,0 +1,92 @@
package devianter
import (
"strconv"
"strings"
)
// структура группы или пользователя
type Group struct {
ErrorDescription string
Owner struct {
Group bool `json:"isGroup"`
Username string
}
Gruser struct {
ID int `json:"gruserId"`
Page struct {
Modules []struct {
Name string
ModuleData struct {
About struct {
Country, Website, WebsiteLabel, Gender, Tagline string
DeviantFor int64
SocialLinks []struct {
Value string
}
TextContent text
Interests []struct {
Label, Value string
}
}
CoverDeviation struct {
Deviation deviantion `json:"coverDeviation"`
}
// группы
GroupAbout struct {
Tagline string
CreatinDate time `json:"foundationTs"`
Description text
}
GroupAdmins struct {
Results []struct {
Username string
}
}
Folders struct {
Results []struct {
FolderId int
Name string
}
}
// галерея
ModuleData struct {
Folder struct {
Username string
Pages int `json:"totalPageCount"`
Deviations []deviantion
} `json:"folderDeviations"`
}
}
}
}
}
PageExtraData struct {
GruserTagline string
Stats struct {
Deviations, Watchers, Watching, Pageviews, CommentsMade, Favourites, Friends int
FeedComments int `json:"commentsReceivedProfile"`
}
}
}
func UGroup(name string) (g Group) {
ujson("dauserprofile/init/about?username="+name, &g)
return
}
// гарелея пользователя или группы
func Gallery(name string, page int) (g Group) {
var url strings.Builder
url.WriteString("dauserprofile/init/gallery?username=")
url.WriteString(name)
url.WriteString("&page=")
url.WriteString(strconv.Itoa(page))
url.WriteString("&deviations_limit=50&with_subfolders=false")
ujson(url.String(), &g)
return
}