Skip to content

Commit

Permalink
add cna link fetcher and pass test.
Browse files Browse the repository at this point in the history
  • Loading branch information
wedojava committed Sep 29, 2020
1 parent dd7b8c2 commit f9c19d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions internal/fetcher/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func (f *Fetcher) SetLinks() error {
f.Links = append(append(append(newsWorld, newsChina...), realtimeWorld...), realtimeChina...)
case "news.ltn.com.tw":
f.Links = LinksFilter(links, `https://news.*/news/.*`)
case "www.cna.com.tw":
newsFirst := LinksFilter(links, `.*?/news/firstnews/.*`)
newsWorld := LinksFilter(links, `.*?/news/aopl/.*`)
newsPolitical := LinksFilter(links, `.*?/news/aipl/.*`)
newsTW := LinksFilter(links, `.*?/news/acn/.*`)
f.Links = append(append(append(newsFirst, newsWorld...), newsPolitical...), newsTW...)
}
return nil
}
Expand Down
23 changes: 15 additions & 8 deletions internal/fetcher/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@ func TestKickOutLinksMatchPath(t *testing.T) {
}

func TestSetLinks(t *testing.T) {
u, err := url.Parse("https://news.ltn.com.tw/list/breakingnews")
// u, err := url.Parse("https://news.ltn.com.tw/list/breakingnews")
// assertLinks := []string{
// "https://news.ltn.com.tw/news/society/breakingnews/3278253",
// "https://news.ltn.com.tw/news/society/breakingnews/3278250",
// "https://news.ltn.com.tw/news/politics/breakingnews/3278225",
// "https://news.ltn.com.tw/news/politics/breakingnews/3278170",
// }
u, err := url.Parse("https://www.cna.com.tw/list/aall.aspx")
assertLinks := []string{
"https://www.cna.com.tw/news/aopl/202009290075.aspx",
"https://www.cna.com.tw/news/firstnews/202009290051.aspx",
"https://www.cna.com.tw/news/acn/202009290063.aspx",
"https://www.cna.com.tw/news/aipl/202009290055.aspx",
}
if err != nil {
t.Errorf("Url Parse fail!\n%s", err)
}
var f = &Fetcher{
Entrance: u,
}
f.SetLinks()
assertLinks := []string{
"https://news.ltn.com.tw/news/society/breakingnews/3278253",
"https://news.ltn.com.tw/news/society/breakingnews/3278250",
"https://news.ltn.com.tw/news/politics/breakingnews/3278225",
"https://news.ltn.com.tw/news/politics/breakingnews/3278170",
}
shot := 0
for _, link := range f.Links {
for _, v := range assertLinks {
Expand All @@ -39,7 +46,7 @@ func TestSetLinks(t *testing.T) {
}
}
}
if shot == 0 {
if shot != len(assertLinks) {
t.Errorf("want: %v, got: %v", len(assertLinks), shot)
}
}

0 comments on commit f9c19d0

Please # to comment.