mirror of
https://bitbucket.org/skobkin/point-tools-crawler.git
synced 2024-12-04 18:25:52 +00:00
Namespace change. Test point-tools request implementation
This commit is contained in:
parent
6e2664d6d3
commit
9e1adb2867
|
@ -5,10 +5,11 @@ import (
|
|||
"fmt"
|
||||
//"gopkg.in/yaml.v2"
|
||||
//"net/http"
|
||||
"bitbucket.org/skobkin/point_post_crawler/point"
|
||||
"bitbucket.org/skobkin/point-tools-crawler/point"
|
||||
"time"
|
||||
"log"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
|
||||
|
@ -45,6 +46,7 @@ func main() {
|
|||
|
||||
fmt.Printf("1 page requested\n")
|
||||
printPageJSON(page)
|
||||
sendPage(page)
|
||||
|
||||
pageNumber := 1;
|
||||
|
||||
|
@ -59,6 +61,7 @@ func main() {
|
|||
}
|
||||
|
||||
printPageJSON(page)
|
||||
sendPage(page)
|
||||
|
||||
fmt.Printf("%d page requested\n", pageNumber)
|
||||
fmt.Printf("%d posts\n", len(page.Posts))
|
||||
|
@ -67,13 +70,47 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func printPageJSON(page point.Page) {
|
||||
func getPageJSON(page point.Page) (string, error) {
|
||||
b, err := json.Marshal(page)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
fmt.Println(string(b[:]))
|
||||
return string(b[:]), nil
|
||||
}
|
||||
|
||||
func printPageJSON(page point.Page) {
|
||||
json, err := getPageJSON(page)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("JSON print error")
|
||||
}
|
||||
|
||||
fmt.Println(json)
|
||||
}
|
||||
|
||||
func sendPage(page point.Page) error {
|
||||
json, err := getPageJSON(page)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := point.Client{}
|
||||
|
||||
data := url.Values{}
|
||||
data.Set("token", "test_token")
|
||||
data.Add("json", json)
|
||||
|
||||
body, req_err := client.MakePostRequest("http://point-tools.local:8000/api/crawler/all/page", data)
|
||||
|
||||
if req_err != nil {
|
||||
return req_err
|
||||
}
|
||||
|
||||
fmt.Println("Response:", string(body[:]))
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue