Skip to content

Commit

Permalink
fix bug after refine architect
Browse files Browse the repository at this point in the history
  • Loading branch information
kkdai committed Nov 6, 2021
1 parent a9d1e5f commit 059c04e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion ptt.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,14 @@ func (p *PTT) GetPostStarByIndex(postIndex int) int {
return p.storedPost[postIndex].Likeint
}

//Set Ptt board psot number, fetch assigned number of posts.
func (p *PTT) ParsePttByNumber(num int) {

return
}

//Set Ptt board page index, fetch all post and return article count back
func (p *PTT) ParsePttPageByIndex(page int) int {
func (p *PTT) ParsePttPageByIndex(page int, replace bool) int {
// Get https response with setting cookie over18=1
resp := getResponseWithCookie(p.entryAddress)
doc, err := goquery.NewDocumentFromResponse(resp)
Expand Down Expand Up @@ -234,6 +240,11 @@ func (p *PTT) ParsePttPageByIndex(page int) int {
posts = append(posts, newPost)
}
})
if replace {
p.storedPost = posts
} else {
p.storedPost = append(p.storedPost, posts...)
}

return len(p.storedPost)
}
Expand Down
10 changes: 9 additions & 1 deletion ptt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package photomgr

import "testing"

func TestGetPage(t *testing.T) {
ptt := NewPTT()
count := ptt.ParsePttPageByIndex(0, true)
if count == 0 {
t.Errorf("ParsePttPageByIndex: no content")
}
}

func TestURLPhoto(t *testing.T) {
ptt := NewPTT()
title := ptt.GetPostTitleByIndex(5)
Expand Down Expand Up @@ -36,7 +44,7 @@ func TestURLLike(t *testing.T) {

func TestUAllGirls(t *testing.T) {
ptt := NewPTT()
count := ptt.ParsePttPageByIndex(0)
count := ptt.ParsePttPageByIndex(0, true)
for i := 0; i < count; i++ {
title := ptt.GetPostTitleByIndex(i)
if CheckTitleWithBeauty(title) {
Expand Down

0 comments on commit 059c04e

Please sign in to comment.