mirror of
https://git.macaw.me/skunky/devianter.git
synced 2025-04-27 19:45:08 +03:00
First Commit!
This commit is contained in:
parent
3334c33e04
commit
66ab740d7f
8 changed files with 434 additions and 0 deletions
79
comments.go
Normal file
79
comments.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package devianter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type comments struct {
|
||||
Cursor string
|
||||
PrevOffset int
|
||||
HasMore, HasLess bool
|
||||
|
||||
Total int
|
||||
Thread []struct {
|
||||
CommentId, ParentId, Replies, Likes int
|
||||
Posted time
|
||||
IsAuthorHighlited bool
|
||||
|
||||
Desctiption string
|
||||
|
||||
// упрощение структуры с комментами
|
||||
Comment string
|
||||
|
||||
TextContent struct {
|
||||
Html struct {
|
||||
Markup string
|
||||
}
|
||||
}
|
||||
|
||||
User struct {
|
||||
Username string
|
||||
IsBanned bool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// функция для обработки комментариев поста, пользователя, группы и многого другого
|
||||
func Comments(
|
||||
postid string,
|
||||
cursor string,
|
||||
page int,
|
||||
typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
|
||||
) (cmmts comments) {
|
||||
for x := 0; x <= page; x++ {
|
||||
ujson(
|
||||
"dashared/comments/thread?typeid="+strconv.Itoa(typ)+
|
||||
"&itemid="+postid+"&maxdepth=1000&order=newest"+
|
||||
"&limit=50&cursor="+strings.ReplaceAll(cursor, "+", `%2B`),
|
||||
&cmmts,
|
||||
)
|
||||
|
||||
cursor = cmmts.Cursor
|
||||
|
||||
// парсинг json внутри json
|
||||
for i := 0; i < len(cmmts.Thread); i++ {
|
||||
m, l := cmmts.Thread[i].TextContent.Html.Markup, len(cmmts.Thread[i].TextContent.Html.Markup)
|
||||
cmmts.Thread[i].Comment = m
|
||||
|
||||
// если начало строки {, а конец }, то срабатывает этот иф
|
||||
if m[0] == 123 && m[l-1] == 125 {
|
||||
var content struct {
|
||||
Blocks []struct {
|
||||
Text string
|
||||
}
|
||||
}
|
||||
|
||||
e := json.Unmarshal([]byte(m), &content)
|
||||
err(e)
|
||||
|
||||
for _, a := range content.Blocks {
|
||||
cmmts.Thread[i].Comment = a.Text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue