fix: ParseDuration Method

add: store UpdateOperator
This commit is contained in:
eson
2020-07-16 16:22:14 +08:00
parent 7e3b36c7d0
commit fe25921f9a
6 changed files with 55 additions and 9 deletions

View File

@@ -1,2 +1,3 @@
*.html
screenlog.*
screenlog.*
openrec

View File

@@ -11,5 +11,6 @@ package main
*/
func main() {
oe := &OpenrecExtractor{}
oe.Execute()
}

View File

@@ -136,7 +136,7 @@ func (oe *OpenrecExtractor) extractLive(clog intimate.ISet) {
func (oe *OpenrecExtractor) extractTags(clog intimate.ISet) {
var tags []string
matheslist := regexp.MustCompile(`TagButton__Button[^>]+>(.{1,100})</a`).FindAllStringSubmatch(oe.userLive.GetSource().Str, -1)
matheslist := regexp.MustCompile(`<a.+TagButton__Button[^>]+>(.{1,100})</a>`).FindAllStringSubmatch(oe.userLive.GetSource().Str, -1)
for _, m := range matheslist {
tags = append(tags, m[1])
}
@@ -150,16 +150,19 @@ func (oe *OpenrecExtractor) extractTags(clog intimate.ISet) {
}
func (oe *OpenrecExtractor) Execute() {
collect := intimate.NewExtractorStore()
store := intimate.NewSourceStore("source_openrec")
for {
source, err := store.Pop(string(intimate.TTOpenrecRanking), 100)
if err != nil {
log.Println(err)
return
}
source.SetOperator(int32(intimate.OperatorError))
anchorId := source.GetSource().String
ai := &intimate.AnchorInfo{}
@@ -167,12 +170,10 @@ func (oe *OpenrecExtractor) Execute() {
ai.SetPlatform(string(intimate.Popenrec))
sdata := source.GetExt().([]byte)
if gjson.ValidBytes(sdata) {
result := gjson.ParseBytes(sdata)
datamap := result.Map()
oe := &OpenrecExtractor{}
oe.user = intimate.NewExtractorSource(datamap["user"])
oe.user.CreateExtractor()
@@ -198,6 +199,8 @@ func (oe *OpenrecExtractor) Execute() {
Uid, err := collect.InsertAnchorInfo(ai)
if err != nil {
log.Println(err)
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
store.UpdateOperator(source)
return
}
@@ -206,7 +209,14 @@ func (oe *OpenrecExtractor) Execute() {
clog.Set("AnchorId", anchorId)
clog.Set("UpdateTime", source.GetUpdateTime())
collect.InsertCollectLog(clog)
if err = collect.InsertCollectLog(clog); err != nil {
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
store.UpdateOperator(source)
return
}
source.SetOperator(int32(intimate.OperatorExtractorOK))
store.UpdateOperator(source)
} else {
log.Println("data is not json:\n", string(sdata))
}

View File

@@ -100,11 +100,13 @@ func TestExtractor(t *testing.T) {
for {
source, err := store.Pop(string(intimate.TTOpenrecRanking), 100)
if err != nil {
log.Println(err)
return
}
source.SetOperator(int32(intimate.OperatorError))
anchorId := source.GetSource().String
ai := &intimate.AnchorInfo{}
@@ -112,7 +114,6 @@ func TestExtractor(t *testing.T) {
ai.SetPlatform(string(intimate.Popenrec))
sdata := source.GetExt().([]byte)
if gjson.ValidBytes(sdata) {
result := gjson.ParseBytes(sdata)
datamap := result.Map()
@@ -143,6 +144,8 @@ func TestExtractor(t *testing.T) {
Uid, err := collect.InsertAnchorInfo(ai)
if err != nil {
t.Error(err)
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
store.UpdateOperator(source)
return
}
@@ -151,7 +154,14 @@ func TestExtractor(t *testing.T) {
clog.Set("AnchorId", anchorId)
clog.Set("UpdateTime", source.GetUpdateTime())
collect.InsertCollectLog(clog)
if err = collect.InsertCollectLog(clog); err != nil {
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
store.UpdateOperator(source)
return
}
source.SetOperator(int32(intimate.OperatorExtractorOK))
store.UpdateOperator(source)
} else {
t.Error("data is not json:\n", string(sdata))
}