最新
This commit is contained in:
parent
274355f415
commit
cbad28f7c6
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
|
@ -39,19 +38,28 @@ func (te *TaskEx) Execute(glocal map[string]interface{}) imitater.ITask {
|
|||
}
|
||||
|
||||
var adDataList []string
|
||||
rule := regexp.MustCompile(`\\"label\\"\:\\"广告\\"|\\"label_style\\"\:3`)
|
||||
if rule.MatchString(resp.Content()) {
|
||||
if gjson.Valid(resp.Content()) {
|
||||
P := gjson.Parse(resp.Content())
|
||||
gADDate := P.Get(`data.ordered_info.#.ad_data`)
|
||||
if gADDate.Exists() {
|
||||
for _, result := range gADDate.Array() {
|
||||
|
||||
if gjson.Valid(resp.Content()) {
|
||||
P := gjson.Parse(resp.Content())
|
||||
data := P.Get(`data`)
|
||||
if data.Exists() {
|
||||
adData := data.Get(`ordered_info.#.ad_data`)
|
||||
if adData.Exists() {
|
||||
for _, result := range adData.Array() {
|
||||
adDataList = append(adDataList, result.String())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Println("be careful:", resp.Content())
|
||||
|
||||
relatedVideo := data.Get(`related_video_toutiao.#[show_tag = "广告"]#`)
|
||||
if adData.Exists() {
|
||||
for _, result := range relatedVideo.Array() {
|
||||
adDataList = append(adDataList, result.String())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
log.Println("be careful:", resp.Content())
|
||||
}
|
||||
|
||||
if imitater.ADDataSave(te, te.db, adDataList) {
|
||||
|
|
|
@ -2,31 +2,45 @@ package main
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestTaskEx_Execute(t *testing.T) {
|
||||
rule := regexp.MustCompile(`\\"label\\"\:\\"广告\\"|\\"label_style\\"\:3`)
|
||||
data, err := ioutil.ReadFile("../s.json")
|
||||
data, err := ioutil.ReadFile("../ssss.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println(rule.MatchString(string(data)))
|
||||
log.Println(gjson.Valid(string(data)))
|
||||
|
||||
P := gjson.Parse(string(data))
|
||||
gADDate := P.Get(`data.ordered_info.#.ad_data`)
|
||||
log.Println(gADDate.Exists(), gADDate.IsArray())
|
||||
var adDataList []string
|
||||
if gjson.Valid(string(data)) {
|
||||
P := gjson.Parse(string(data))
|
||||
data := P.Get(`data`)
|
||||
if data.Exists() {
|
||||
adData := data.Get(`ordered_info.#.ad_data`)
|
||||
if adData.Exists() {
|
||||
for _, result := range adData.Array() {
|
||||
adDataList = append(adDataList, result.String())
|
||||
}
|
||||
} else {
|
||||
t.Error(`ordered_info.#.ad_data not exists`)
|
||||
}
|
||||
|
||||
if !(gADDate.Exists() && gADDate.IsArray()) {
|
||||
t.Error("path is error")
|
||||
relatedVideo := data.Get(`related_video_toutiao.#[show_tag = "广告"]#`)
|
||||
if adData.Exists() {
|
||||
for _, result := range relatedVideo.Array() {
|
||||
adDataList = append(adDataList, result.String())
|
||||
}
|
||||
} else {
|
||||
t.Error(`related_video_toutiao.#[show_tag = "广告"]# not exists`)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for _, result := range gADDate.Array() {
|
||||
log.Println(gjson.Valid(result.Raw))
|
||||
if len(adDataList) != 2 {
|
||||
t.Error("adDataList != 2")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
21
info/info.go
21
info/info.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
crontab "474420502.top/eson/crontabex"
|
||||
"474420502.top/eson/gjson"
|
||||
|
@ -37,19 +36,17 @@ func (te *TaskEx) Execute(glocal map[string]interface{}) imitater.ITask {
|
|||
}
|
||||
|
||||
var adDataList []string
|
||||
rule := regexp.MustCompile(`\\"label\\"\:\\"广告\\"|\\"label_style\\"\:3`)
|
||||
if rule.MatchString(resp.Content()) {
|
||||
if gjson.Valid(resp.Content()) {
|
||||
P := gjson.Parse(resp.Content())
|
||||
gADDate := P.Get(`data.#[content ~ @label_style\":3@ ]#.content`)
|
||||
if gADDate.Exists() {
|
||||
for _, result := range gADDate.Array() {
|
||||
adDataList = append(adDataList, result.String())
|
||||
}
|
||||
|
||||
if gjson.Valid(resp.Content()) {
|
||||
P := gjson.Parse(resp.Content())
|
||||
gADDate := P.Get(`data.#[content ~ @"label":"广告"@ ]#.content`)
|
||||
if gADDate.Exists() {
|
||||
for _, result := range gADDate.Array() {
|
||||
adDataList = append(adDataList, result.String())
|
||||
}
|
||||
} else {
|
||||
log.Println("be careful:", resp.Content())
|
||||
}
|
||||
} else {
|
||||
log.Println("be careful:", resp.Content())
|
||||
}
|
||||
|
||||
if imitater.ADDataSave(te, te.db, adDataList) {
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestTaskEx_Execute(t *testing.T) {
|
|||
log.Println(gjson.Valid(string(data)))
|
||||
|
||||
P := gjson.Parse(string(data))
|
||||
gADDate := P.Get(`data.#[content ~ @label_style\":3@ ]#.content`)
|
||||
gADDate := P.Get(`data.#[content ~ @"label":"广告"@ ]#.content`)
|
||||
log.Println(gADDate.Exists(), gADDate.IsArray())
|
||||
|
||||
if !(gADDate.Exists() && gADDate.IsArray()) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user