Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
feat: now include key will check on tiile and content
Browse files Browse the repository at this point in the history
  • Loading branch information
itning committed Jul 12, 2020
1 parent d8e74d7 commit 9cfb6ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ func Open(onStart func(p preference.Preference)) {
hyperLink,
widget.NewLabel("设置豆瓣群组链接:"),
groupUrlEntry,
widget.NewLabel("设置Cookie(如果遇到nil请设置):"),
widget.NewLabel("设置Cookie(如果遇到\"nil\"请设置该项):"),
cookieEntry,
widget.NewLabel("设置爬取页数:"),
maxPageEntry,
widget.NewLabel("设置最大价格:"),
maxPriceEntry,
widget.NewLabel("设置标题爬取关键字(用|分隔,不写全爬):"),
widget.NewLabel("设置标题或内容爬取关键字(用|分隔,不写全爬):"),
includeKeyEntry,
widget.NewLabel("设置标题和内容排除关键字(用|分隔):"),
widget.NewLabel("设置标题或内容排除关键字(用|分隔,不写全爬):"),
excludeKeyEntry,
isIncludeNoContentPriceCheck,
isSavePreferenceCheck,
Expand Down
26 changes: 20 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var dataArray = make(markdown.DataArray, 0)
var pre preference.Preference

func main() {
//handleArgs()
gui.Open(func(p preference.Preference) {
pre = p
savePreference(&p)
Expand Down Expand Up @@ -89,9 +88,6 @@ func each(nodes xpath.Nodes, request request.Data) {
hrefs := nodes.Attr("href")
titles := nodes.Attr("title")
for index, href := range hrefs {
if !isIncludeContent(titles[index]) {
continue
}
if isExcludeContent(titles[index]) {
continue
}
Expand Down Expand Up @@ -122,6 +118,17 @@ func isIncludeContent(content string) bool {
return false
}

// 只要关键字在标题或内容中即返回真
func checkTitleOrContentHaveKey(title string, content string) bool {
if isIncludeContent(title) {
return true
} else if isIncludeContent(content) {
return true
} else {
return false
}
}

func isExcludeContent(content string) bool {
for _, key := range pre.ExcludeKeyArray {
if strings.Contains(content, key) {
Expand Down Expand Up @@ -155,6 +162,9 @@ func content(nodes xpath.Nodes, request request.Data) {
if isExcludeContent(content) {
continue
}
if !checkTitleOrContentHaveKey(title, content) {
continue
}
// 处理图片
imgArray := handleImages(node)
// 处理时间
Expand Down Expand Up @@ -185,12 +195,16 @@ func contentWithTitleNoPrice(nodes xpath.Nodes, request request.Data) {
if isExcludeContent(content) {
continue
}
// 处理标题
title := handleTitle(node)

if !checkTitleOrContentHaveKey(title, content) {
continue
}
// 处理图片
imgArray := handleImages(node)
// 处理时间
timeStr := handleTime(node)
// 处理标题
title := handleTitle(node)

dataArray.Append(markdown.Data{
TimeString: timeStr,
Expand Down

0 comments on commit 9cfb6ee

Please sign in to comment.