/
main.go
70 lines (49 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"context"
"fmt"
"strings"
// grpc...
selserv "github.com/FishyFish3r/crypto-parser/Parser/pkg/selserv"
"github.com/PuerkitoBio/goquery"
"google.golang.org/grpc"
)
func checkError(err error) bool {
if err != nil {
fmt.Println(err.Error())
return false
}
return true
}
type Coin struct {
Name string
PriceKZT string
PriceRUB string
}
func parseBinancePrice(url string, c selserv.SeleniumServerClient) string {
resp, _ := c.GetHtml(context.Background(), &selserv.HtmlArgs{Url: url})
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(resp.GetHtml()))
price := doc.Find(".showPrice").Text()
return price
}
func parseCryptoruPrice(url string, c selserv.SeleniumServerClient) string {
resp, _ := c.GetHtml(context.Background(), &selserv.HtmlArgs{Url: url})
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(resp.GetHtml()))
price := doc.Find(".coin__price-value").Text()
price = strings.TrimSpace(price)
return price
}
func main() {
conn, err := grpc.Dial(":61337", grpc.WithInsecure())
if !checkError(err) {
return
}
client := selserv.NewSeleniumServerClient(conn)
for {
var coin Coin
coin.Name = "USDT"
coin.PriceRUB = parseBinancePrice("https://www.binance.com/en/trade/USDT_RUB", client)
coin.PriceKZT = parseCryptoruPrice("https://crypto.ru/usdt-kzt/", client)
fmt.Printf("1 %s = \n\tRUB:%s\n\tKZT:%s\n", coin.Name, coin.PriceRUB, coin.PriceKZT)
}
}