mirror of
https://bitbucket.org/skobkin/point-tools-crawler.git
synced 2024-12-04 18:25:52 +00:00
Point-tools server response processing. Small refactoring.
This commit is contained in:
parent
24f532d6f1
commit
8502252e8f
|
@ -7,6 +7,7 @@ import (
|
||||||
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
|
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -24,53 +25,73 @@ func main() {
|
||||||
pointClient := point.NewClient("https://point.im/api/")
|
pointClient := point.NewClient("https://point.im/api/")
|
||||||
pointToolsClient := point_tools.NewClient("http://point-tools.local:8000/api/crawler/")
|
pointToolsClient := point_tools.NewClient("http://point-tools.local:8000/api/crawler/")
|
||||||
|
|
||||||
_, login_err := pointClient.Login(login, password)
|
_, loginErr := pointClient.Login(login, password)
|
||||||
|
|
||||||
if login_err != nil {
|
if loginErr != nil {
|
||||||
fmt.Printf("Login error %s", login_err)
|
fmt.Printf("Login error %s", loginErr)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Successfully authenticated!\n")
|
fmt.Printf("Successfully authenticated!\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
page, req_err := pointClient.GetRecentAllPostsPage()
|
page, reqErr := pointClient.GetRecentAllPostsPage()
|
||||||
|
|
||||||
if req_err != nil {
|
if reqErr != nil {
|
||||||
log.Fatal(req_err)
|
log.Fatal(reqErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("1 page requested\n")
|
fmt.Printf("1 page requested\n")
|
||||||
|
|
||||||
if len(page.Posts) == 0 {
|
if len(page.Posts) > 0 {
|
||||||
fmt.Println("Last uid", string(page.Posts[len(page.Posts)-1].Uid))
|
fmt.Println("Last uid", strconv.Itoa(page.Posts[len(page.Posts)-1].Uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
pointToolsClient.SendPage(page)
|
sendResp, sendErr := pointToolsClient.SendPage(page)
|
||||||
|
|
||||||
//var str string
|
if sendErr != nil {
|
||||||
|
log.Fatal(sendErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if point_tools.STATUS_SUCCESS != sendResp.Status || false == sendResp.Data.Continue {
|
||||||
|
fmt.Println("API rejected next page request")
|
||||||
|
fmt.Println("Exiting.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
pageNumber := 1
|
pageNumber := 1
|
||||||
|
|
||||||
for page.HasNext {
|
for page.HasNext {
|
||||||
pageNumber++
|
pageNumber++
|
||||||
|
|
||||||
page, req_err = pointClient.GetNextAllPostsPage(page)
|
page, reqErr = pointClient.GetNextAllPostsPage(page)
|
||||||
|
|
||||||
if req_err != nil {
|
if reqErr != nil {
|
||||||
log.Fatal(req_err)
|
log.Fatal(reqErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%d page requested", pageNumber)
|
||||||
|
if len(page.Posts) > 0 {
|
||||||
|
fmt.Printf(", last uid %d", page.Posts[len(page.Posts)-1].Uid)
|
||||||
|
}
|
||||||
|
fmt.Printf(" -> %d posts\n", len(page.Posts))
|
||||||
|
|
||||||
|
sendResp, sendErr := pointToolsClient.SendPage(page)
|
||||||
|
|
||||||
fmt.Printf("%d page requested, last uid: %d", pageNumber)
|
if sendErr != nil {
|
||||||
fmt.Printf("%d posts\n", len(page.Posts))
|
log.Fatal(sendErr)
|
||||||
|
}
|
||||||
|
|
||||||
pointToolsClient.SendPage(page)
|
if point_tools.STATUS_SUCCESS != sendResp.Status || false == sendResp.Data.Continue {
|
||||||
|
fmt.Println("API rejected next page request")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Exiting.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,5 @@ func (c *PointToolsClient) SendPage(page point.Page) (ReceiveAllPageResponse, er
|
||||||
return response, json_err
|
return response, json_err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Response:", string(body[:]))
|
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
|
@ -1,5 +1,10 @@
|
||||||
package point_tools
|
package point_tools
|
||||||
|
|
||||||
|
const (
|
||||||
|
STATUS_SUCCESS string = "success"
|
||||||
|
STATUS_FAILURE string = "fail"
|
||||||
|
)
|
||||||
|
|
||||||
type ReceiveAllPageResponse struct {
|
type ReceiveAllPageResponse struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Data ReceiveAllPageData `json:"data"`
|
Data ReceiveAllPageData `json:"data"`
|
||||||
|
|
Loading…
Reference in a new issue