|
@@ -17,7 +17,6 @@ import (
|
|
|
//go:embed dom.json
|
|
|
var domJson string
|
|
|
var domMap map[string]string
|
|
|
-var maxId int
|
|
|
|
|
|
func init() {
|
|
|
domMap = map[string]string{}
|
|
@@ -26,33 +25,26 @@ func init() {
|
|
|
panic(err)
|
|
|
}
|
|
|
db.Init()
|
|
|
- db.New("t_config").Attr("value").Where("name", "prev_loop_new_id").GetRow().Scan(&maxId)
|
|
|
- fmt.Println("startTask at maxId ", maxId)
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- for {
|
|
|
- newMaxId := loopMaxId(maxId)
|
|
|
- if maxId >= newMaxId {
|
|
|
- fmt.Println("finishTask at maxId ", maxId)
|
|
|
- db.Pool().Update("t_config", map[string]interface{}{"value": maxId}, map[string]interface{}{"name": "prev_loop_new_id"})
|
|
|
- return
|
|
|
- }
|
|
|
- maxId = newMaxId
|
|
|
- loopMaxId(maxId)
|
|
|
- }
|
|
|
+ loopBrief()
|
|
|
+ loopPicture()
|
|
|
}
|
|
|
|
|
|
-func loopMaxId(maxId int) int {
|
|
|
- list, err := db.New("t_news").Attr("id,content,url").WhereF("id > ?", maxId).Order("ORDER BY id asc").Limit(0, 100).GetAll()
|
|
|
- fmt.Println("loopLen", len(list), err)
|
|
|
+func loopBrief() {
|
|
|
+ list, err := db.New("t_news").Attr("id,content,url").Where("status", "Brief").GetAll()
|
|
|
+ fmt.Println("loopBrief", len(list), err)
|
|
|
for _, record := range list {
|
|
|
update := map[string]interface{}{}
|
|
|
id := record["id"].(int64)
|
|
|
- idInt := int(id)
|
|
|
- content := record["content"].(string)
|
|
|
- url := record["url"].(string)
|
|
|
- brief := ""
|
|
|
+ var content, url, brief string
|
|
|
+ if val, flag := record["content"].(string); flag {
|
|
|
+ content = val
|
|
|
+ }
|
|
|
+ if val, flag := record["url"].(string); flag {
|
|
|
+ url = val
|
|
|
+ }
|
|
|
if len(content) >= 1024 {
|
|
|
brief = genBrief(content)
|
|
|
update["brief"] = brief
|
|
@@ -69,28 +61,57 @@ func loopMaxId(maxId int) int {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // maxId更新
|
|
|
- if maxId < idInt {
|
|
|
- maxId = idInt
|
|
|
- }
|
|
|
//
|
|
|
if brief == "" {
|
|
|
update["status"] = "Delete"
|
|
|
} else {
|
|
|
- update["status"] = "Publish"
|
|
|
+ update["status"] = "Picture"
|
|
|
tags := genTag(brief)
|
|
|
if tags != "" {
|
|
|
alltag := do_insert_tag(id, tags)
|
|
|
update["tag"] = alltag
|
|
|
update["pics"] = get_pics(alltag)
|
|
|
+ update["status"] = "Publish"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println("finishBrief", id, brief)
|
|
|
+ if _, err := db.Pool().Update("t_news", update, map[string]interface{}{"id": id}); err != nil {
|
|
|
+ fmt.Println("save", err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func loopPicture() {
|
|
|
+ list, _ := db.New("t_news").Attr("id,tag,brief").Where("status", "Picture").GetAll()
|
|
|
+ for _, record := range list {
|
|
|
+ update := map[string]interface{}{}
|
|
|
+ id := record["id"].(int64)
|
|
|
+ var brief, tags string
|
|
|
+ if val, flag := record["brief"].(string); flag {
|
|
|
+ brief = val
|
|
|
+ }
|
|
|
+ if val, flag := record["tag"].(string); flag {
|
|
|
+ tags = val
|
|
|
+ }
|
|
|
+ if tags == "" {
|
|
|
+ tags = genTag(brief)
|
|
|
+ if tags != "" {
|
|
|
+ alltag := do_insert_tag(id, tags)
|
|
|
+ update["tag"] = alltag
|
|
|
+ update["pics"] = get_pics(alltag)
|
|
|
+ update["status"] = "Publish"
|
|
|
+ } else {
|
|
|
+ update["status"] = "Delete"
|
|
|
}
|
|
|
+ } else {
|
|
|
+ update["pics"] = get_pics(tags)
|
|
|
+ update["status"] = "Publish"
|
|
|
}
|
|
|
- fmt.Println("finish", id, brief)
|
|
|
+ fmt.Println("finishPicture", id, tags)
|
|
|
if _, err := db.Pool().Update("t_news", update, map[string]interface{}{"id": id}); err != nil {
|
|
|
fmt.Println("save", err.Error())
|
|
|
}
|
|
|
}
|
|
|
- return maxId
|
|
|
}
|
|
|
|
|
|
func genBrief(content string) string {
|
|
@@ -123,7 +144,7 @@ func genTag(content string) string {
|
|
|
Messages: []openai.ChatCompletionMessage{
|
|
|
{
|
|
|
Role: openai.ChatMessageRoleUser,
|
|
|
- Content: content + "\r\n以上新闻内容属于哪一类新闻 A居民 B商业 C金融 D建筑 E屋内装饰 \r\n可以选一项或者两项",
|
|
|
+ Content: content + "\r\n以上新闻内容属于哪一类 A居民 B商业 C金融 D建筑 E屋内装饰 F其它\r\n仅可选一项或者两项",
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -155,6 +176,7 @@ func do_insert_tag(id int64, tags string) string {
|
|
|
"C": "financial",
|
|
|
"D": "construction",
|
|
|
"E": "indoor",
|
|
|
+ "F": "other",
|
|
|
}
|
|
|
mtags := []string{}
|
|
|
for opt, tag := range mtag {
|