point-tools-crawler/point_post_crawler.go

77 lines
1.4 KiB
Go
Raw Normal View History

2016-03-07 20:04:50 +00:00
package main
import (
"flag"
2016-03-15 22:21:50 +00:00
"fmt"
"bitbucket.org/skobkin/point-tools-crawler/point"
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
2016-03-07 20:04:50 +00:00
"log"
"time"
2016-03-07 20:04:50 +00:00
)
func main() {
2016-03-15 22:21:50 +00:00
var login, password string
2016-03-07 20:04:50 +00:00
flag.StringVar(&login, "l", "", "Account login")
flag.StringVar(&password, "p", "", "Account password")
flag.Parse()
if len(login) < 1 || len(password) < 1 {
fmt.Printf("Login and password must be defined")
return
}
pointClient := point.NewClient("https://point.im/api/")
pointToolsClient := point_tools.NewClient("http://point-tools.local:8000/api/crawler/")
2016-03-07 20:04:50 +00:00
_, login_err := pointClient.Login(login, password)
2016-03-07 20:04:50 +00:00
2016-03-15 22:21:50 +00:00
if login_err != nil {
fmt.Printf("Login error %s", login_err)
return
} else {
fmt.Printf("Successfully authenticated!\n")
}
2016-03-07 20:04:50 +00:00
page, req_err := pointClient.GetRecentAllPostsPage()
2016-03-07 20:04:50 +00:00
2016-03-15 22:21:50 +00:00
if req_err != nil {
log.Fatal(req_err)
return
}
2016-03-07 20:04:50 +00:00
2016-03-15 22:21:50 +00:00
fmt.Printf("1 page requested\n")
2016-03-07 20:04:50 +00:00
if len(page.Posts) == 0 {
fmt.Println("Last uid", string(page.Posts[len(page.Posts)-1].Uid))
}
pointToolsClient.SendPage(page)
//var str string
pageNumber := 1
2016-03-07 20:04:50 +00:00
2016-03-15 22:21:50 +00:00
for page.HasNext {
pageNumber++
2016-03-07 20:04:50 +00:00
page, req_err = pointClient.GetNextAllPostsPage(page)
2016-03-07 20:04:50 +00:00
2016-03-15 22:21:50 +00:00
if req_err != nil {
log.Fatal(req_err)
return
2016-03-07 20:04:50 +00:00
}
2016-03-15 22:56:51 +00:00
2016-03-07 20:04:50 +00:00
fmt.Printf("%d page requested, last uid: %d", pageNumber)
fmt.Printf("%d posts\n", len(page.Posts))
pointToolsClient.SendPage(page)
time.Sleep(time.Second)
2016-03-07 20:04:50 +00:00
}
}
2016-03-15 22:21:50 +00:00