You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

package main
import (
"container/list"
"database/sql"
"keyword_analyse/config"
"keyword_analyse/entity"
"strings"
_ "github.com/mattn/go-sqlite3"
)
func main() {
config.InitConfig()
config.Logger.Info("aaaaa")
db, err := sql.Open("sqlite3", "E:/code/youtube_prod/db/youtube_prod.db")
if err != nil {
config.Logger.Fatal(err)
}
defer db.Close()
config.Logger.Info("连接成功")
// 获取关键字
keyWordList := list.New()
SrtFileList := list.New()
keyWordRows, err := db.Query("SELECT * FROM keyWord")
if err != nil {
config.Logger.Fatal(err)
}
defer keyWordRows.Close()
for keyWordRows.Next() {
// entity := &entity.KeyWord{1, "aa", "aaa"}
entity := new(entity.KeyWord)
if err := keyWordRows.Scan(&entity.Id, &entity.Region, &entity.Word); err != nil {
config.Logger.Fatal(err)
}
keyWordList.PushBack(entity)
}
// 获取未匹配的字幕
rows, err := db.Query("SELECT * FROM srtFile WHERE isScan = 0")
if err != nil {
config.Logger.Fatal(err)
}
defer rows.Close()
for rows.Next() {
entity := new(entity.SrtFile)
if err := rows.Scan(&entity.Id, &entity.VideoId, &entity.ChannelId, &entity.Ordinal, &entity.SrtStartTime, &entity.SrtEndTime, &entity.SrtText, &entity.IsScan); err != nil {
config.Logger.Fatal(err)
}
SrtFileList.PushBack(entity)
}
config.Logger.Infof("keyWordLen:%d,srtFileLen:%d", keyWordList.Len(), SrtFileList.Len())
for e := SrtFileList.Front(); e != nil; e = e.Next() {
srtFile := e.Value.(*entity.SrtFile)
go analyse(*srtFile, *keyWordList)
}
}
func analyse(srtFile entity.SrtFile, keyWordList list.List) {
for e := keyWordList.Front(); e != nil; e = e.Next() {
keyWord := e.Value.(*entity.KeyWord)
if strings.Contains(srtFile.SrtText, keyWord.Word) {
config.Logger.Info(keyWord.Word)
} else {
config.Logger.Info("no contains")
}
}
}