mirror of
https://bitbucket.org/skobkin/point-tools-crawler.git
synced 2024-12-05 02:25:53 +00:00
Client now can fetch next pages.
This commit is contained in:
parent
200ff53885
commit
602552baf9
|
@ -8,6 +8,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const point_api_url string = "https://point.im/api/"
|
||||
|
@ -167,7 +168,7 @@ func (c *Client) GetNextAllPostsPage(page Page) (Page, error) {
|
|||
}
|
||||
|
||||
data := url.Values{}
|
||||
data.Add("before", string(page.Posts[len(page.Posts)-1].Uid))
|
||||
data.Add("before", strconv.Itoa(page.Posts[len(page.Posts)-1].Uid))
|
||||
|
||||
body, req_err := c.MakeGetRequest(point_api_url + "all", &data)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"bitbucket.org/skobkin/point_post_crawler/point"
|
||||
"time"
|
||||
"log"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
|
||||
|
@ -43,24 +44,36 @@ func main() {
|
|||
}
|
||||
|
||||
fmt.Printf("1 page requested\n")
|
||||
fmt.Printf("%d posts\n", len(page.Posts))
|
||||
printPageJSON(page)
|
||||
|
||||
pageNumber := 1;
|
||||
|
||||
for page.HasNext {
|
||||
pageNumber++
|
||||
|
||||
page, req_err := client.GetNextAllPostsPage(page)
|
||||
page, req_err = client.GetNextAllPostsPage(page)
|
||||
|
||||
if req_err != nil {
|
||||
log.Fatal(req_err)
|
||||
return
|
||||
}
|
||||
|
||||
printPageJSON(page)
|
||||
|
||||
fmt.Printf("%d page requested\n", pageNumber)
|
||||
fmt.Printf("%d posts\n", len(page.Posts))
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func printPageJSON(page point.Page) {
|
||||
b, err := json.Marshal(page)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
}
|
||||
|
||||
fmt.Println(string(b[:]))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue