2016-03-07 20:04:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2016-03-15 22:21:50 +00:00
|
|
|
"fmt"
|
2016-03-07 20:04:50 +00:00
|
|
|
//"gopkg.in/yaml.v2"
|
|
|
|
//"net/http"
|
2016-03-15 22:21:50 +00:00
|
|
|
"bitbucket.org/skobkin/point_post_crawler/point"
|
2016-03-07 20:04:50 +00:00
|
|
|
"time"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-15 22:21:50 +00:00
|
|
|
client := point.Client{}
|
2016-03-07 20:04:50 +00:00
|
|
|
|
2016-03-15 22:21:50 +00:00
|
|
|
_, login_err := client.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-15 22:21:50 +00:00
|
|
|
page, req_err := client.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")
|
|
|
|
fmt.Printf("%d posts\n", len(page.Posts))
|
2016-03-07 20:04:50 +00:00
|
|
|
|
2016-03-15 22:21:50 +00:00
|
|
|
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-15 22:21:50 +00:00
|
|
|
page, req_err := client.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:21:50 +00:00
|
|
|
fmt.Printf("%d page requested\n", pageNumber)
|
|
|
|
fmt.Printf("%d posts\n", len(page.Posts))
|
2016-03-07 20:04:50 +00:00
|
|
|
|
2016-03-15 22:21:50 +00:00
|
|
|
time.Sleep(2 * time.Second)
|
2016-03-07 20:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-15 22:21:50 +00:00
|
|
|
|