-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.go
49 lines (46 loc) · 1.45 KB
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"errors"
"github.com/soyking/douban-group-spider/filter"
"github.com/soyking/douban-group-spider/flag"
"time"
)
func newFilter(f *flag.Flag) (filter.Filter, error) {
filterFuncs := []filter.FilterFunc{}
if f.AuthorFilterFile != flag.FLAG_AUTHOR_FILTER_DEFAULT {
authors, err := readLines(f.AuthorFilterFile)
if err != nil {
return nil, err
}
filterFuncs = append(filterFuncs, filter.AuthorFilter(authors))
}
if f.TitleFilterFile != flag.FLAG_AUTHOR_FILTER_DEFAULT {
titles, err := readLines(f.TitleFilterFile)
if err != nil {
return nil, err
}
filterFuncs = append(filterFuncs, filter.TitleFilter(titles))
}
if f.ContentFilterFile != flag.FLAG_AUTHOR_FILTER_DEFAULT {
contents, err := readLines(f.ContentFilterFile)
if err != nil {
return nil, err
}
filterFuncs = append(filterFuncs, filter.ContentFilter(contents))
}
if f.ReplyFilter > flag.FLAG_REPLY_FILTER_DEFAULT {
filterFuncs = append(filterFuncs, filter.ReplyLimitFilter(f.ReplyFilter))
}
if f.PicFilter {
// 只对有图片要求的过滤
filterFuncs = append(filterFuncs, filter.PicFilter(true))
}
if f.LastUpdateTimeFilter != flag.FLAG_LAST_UPDATE_TIME_FILTER_DEFAULT {
t, err := time.Parse("2006-01-02 15:04:05", f.LastUpdateTimeFilter)
if err != nil {
return nil, errors.New("check your time format: " + err.Error())
}
filterFuncs = append(filterFuncs, filter.LastUpdateTimeFilter(t))
}
return filter.NewFilter(filterFuncs...), nil
}