-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (45 loc) · 1.02 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
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
const (
FgiApi = "https://fear-and-greed-index.p.rapidapi.com/v1/fgi"
)
func main() {
res := getFearAndGreedIndex()
sendMesage(res)
fmt.Println(res.toJson())
}
func getFearAndGreedIndex() FgiResult {
req, _ := http.NewRequest("GET", FgiApi, nil)
req.Header.Add("X-RapidAPI-Key", os.Getenv("RAPIDAPI_KEY"))
req.Header.Add("X-RapidAPI-Host", "fear-and-greed-index.p.rapidapi.com")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
r := FgiResult{}
err := json.Unmarshal(body, &r)
if err != nil {
panic(err)
}
return r
}
func sendMesage(fr FgiResult) {
bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN"))
if err != nil {
panic(err)
}
//bot.Debug = true
ch, err := strconv.ParseInt(os.Getenv("CHATID"), 10, 64)
m := tgbotapi.NewMessage(ch, fr.toString())
_, err = bot.Send(m)
if err != nil {
panic(err)
}
}