2016-03-07 20:04:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2016-03-15 22:21:50 +00:00
|
|
|
"fmt"
|
2016-03-18 17:47:17 +00:00
|
|
|
"bitbucket.org/skobkin/point-tools-crawler/point"
|
2016-03-20 22:06:34 +00:00
|
|
|
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
|
2016-03-07 20:04:50 +00:00
|
|
|
"log"
|
2016-03-20 22:06:34 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2016-03-20 22:06:34 +00:00
|
|
|
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
|
|
|
|
2016-03-20 22:06:34 +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
|
|
|
|
2016-03-20 22:06:34 +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
|
|
|
|
2016-03-20 22:06:34 +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
|
|
|
|
2016-03-20 22:06:34 +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
|
|
|
|
2016-03-20 22:06:34 +00:00
|
|
|
fmt.Printf("%d page requested, last uid: %d", pageNumber)
|
|
|
|
fmt.Printf("%d posts\n", len(page.Posts))
|
2016-03-18 17:47:17 +00:00
|
|
|
|
2016-03-20 22:06:34 +00:00
|
|
|
pointToolsClient.SendPage(page)
|
2016-03-18 17:47:17 +00:00
|
|
|
|
2016-03-20 22:06:34 +00:00
|
|
|
time.Sleep(time.Second)
|
2016-03-07 20:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-15 22:21:50 +00:00
|
|
|
|
2016-03-18 17:47:17 +00:00
|
|
|
|