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