User implementation and particaly groups
This commit is contained in:
parent
66ab740d7f
commit
9b85088665
17
comments.go
17
comments.go
@ -13,24 +13,21 @@ type comments struct {
|
||||
|
||||
Total int
|
||||
Thread []struct {
|
||||
CommentId, ParentId, Replies, Likes int
|
||||
Replies, Likes int
|
||||
ID int `json:"commentId"`
|
||||
Parent int `json:"ParrentId"`
|
||||
|
||||
Posted time
|
||||
IsAuthorHighlited bool
|
||||
Author bool `json:"isAuthorHighlited"`
|
||||
|
||||
Desctiption string
|
||||
|
||||
// упрощение структуры с комментами
|
||||
Comment string
|
||||
|
||||
TextContent struct {
|
||||
Html struct {
|
||||
Markup string
|
||||
}
|
||||
}
|
||||
TextContent text
|
||||
|
||||
User struct {
|
||||
Username string
|
||||
IsBanned bool
|
||||
Banned bool `json:"isBanned"`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,11 @@ func (t *time) UnmarshalJSON(b []byte) (err error) {
|
||||
type deviantion struct {
|
||||
Title, Url, License string
|
||||
PublishedTime time
|
||||
IsMature, IsAiGenerated, IsDailyDeviation bool
|
||||
|
||||
NSFW bool `json:"isMature"`
|
||||
AI bool `json:"isAiGenerated"`
|
||||
DD bool `json:"isDailyDeviation"`
|
||||
|
||||
Author struct {
|
||||
Username string
|
||||
}
|
||||
@ -54,11 +58,13 @@ type media struct {
|
||||
}
|
||||
|
||||
type text struct {
|
||||
Excerpt string
|
||||
Html struct {
|
||||
Markup, Type string
|
||||
}
|
||||
}
|
||||
|
||||
// структура поста
|
||||
type Deviantion struct {
|
||||
Deviation deviantion
|
||||
Comments struct {
|
||||
@ -73,7 +79,6 @@ type Deviantion struct {
|
||||
}
|
||||
|
||||
IMG, Desctiption string
|
||||
Recomendations []deviantion
|
||||
}
|
||||
|
||||
// для работы функции нужно ID поста и имя пользователя.
|
||||
@ -98,7 +103,7 @@ func Deviation(id string, user string) Deviantion {
|
||||
|
||||
// базовая обработка описания
|
||||
txt := st.Deviation.TextContent.Html.Markup
|
||||
if len(txt) > 0 && txt[0:1] == "{" {
|
||||
if len(txt) > 0 && txt[1] == 125 {
|
||||
var description struct {
|
||||
Blocks []struct {
|
||||
Text string
|
||||
|
@ -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)
|
||||
}
|
@ -2,3 +2,5 @@
|
||||
- emojis
|
||||
- deviantions
|
||||
- comments
|
||||
- search (including gallery search)
|
||||
- users (with gallery)
|
||||
|
45
misc.go
45
misc.go
@ -3,11 +3,11 @@ package devianter
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -118,26 +118,43 @@ func AEmedia(name string, t rune) (string, error) {
|
||||
/* SEARCH */
|
||||
type search struct {
|
||||
Total int `json:"estTotal"`
|
||||
Pages int // only for 'a' scope.
|
||||
Deviations []deviantion
|
||||
Pages int // only for 'a' and 'g' scope.
|
||||
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
|
||||
e = nil
|
||||
|
||||
// о5 построение ссылок.
|
||||
switch scope {
|
||||
case 'a':
|
||||
case 'a': // поиск артов по названию
|
||||
url.WriteString("dabrowse/search/all?q=")
|
||||
case 't':
|
||||
case 't': // поиск артов по тегам
|
||||
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:
|
||||
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)
|
||||
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)
|
||||
|
||||
@ -184,10 +201,14 @@ func puppy(data string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
body := request(
|
||||
fmt.Sprintf("https://www.deviantart.com/_puppy/%s&csrf_token=%s&da_minor_version=20230710", data, token),
|
||||
cookie,
|
||||
)
|
||||
var url strings.Builder
|
||||
url.WriteString("https://www.deviantart.com/_puppy/")
|
||||
url.WriteString(data)
|
||||
url.WriteString("&csrf_token=")
|
||||
url.WriteString(token)
|
||||
url.WriteString("&da_minor_version=20230710")
|
||||
|
||||
body := request(url.String(), cookie)
|
||||
|
||||
// если код ответа не 200, возвращается ошибка
|
||||
if body.Status != 200 {
|
||||
|
5
todo.md
5
todo.md
@ -1,3 +1,2 @@
|
||||
- ~~users~~
|
||||
- ~~groups~~
|
||||
- ~~images in comments~~
|
||||
- groups
|
||||
- images in comments
|
92
user-group.go
Normal file
92
user-group.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user