-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
64 lines (52 loc) · 1.7 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
package main
import (
"encoding/json"
"github.com/rivo/tview"
"io/ioutil"
"net/http"
)
func GetCurr() (string, string, string, string, string, string) {
url := "https://api.coinmarketcap.com/v1/ticker/?limit=6&convert=INR"
res, err := http.Get(url)
if err != nil {
panic(err.Error())
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err.Error())
}
// Accessing Value using empty interface
var value interface{}
err = json.Unmarshal(body, &value)
price := value.([]interface{})
result0 := price[0].(map[string]interface{})
btcPrice := result0["price_inr"].(string)
result1 := price[1].(map[string]interface{})
ethPrice := result1["price_inr"].(string)
result2 := price[2].(map[string]interface{})
xrpPrice := result2["price_inr"].(string)
result3 := price[3].(map[string]interface{})
bchPrice := result3["price_inr"].(string)
result4 := price[4].(map[string]interface{})
adaPrice := result4["price_inr"].(string)
result5 := price[5].(map[string]interface{})
ltcPrice := result5["price_inr"].(string)
return btcPrice, ethPrice, xrpPrice, bchPrice, adaPrice, ltcPrice
}
func main() {
btc, eth, xrp, bch, ada, ltc := GetCurr()
app := tview.NewApplication()
list := tview.NewList().
AddItem("Bitcoin (BTC)", "\u20B9 " + btc, 'a', nil).
AddItem("Ethereum (ETH)", "\u20B9 " + eth, 'b', nil).
AddItem("Ripple (XRP)", "\u20B9 "+ xrp, 'c', nil).
AddItem("Bitcoin Cash (BCH)", "\u20B9 " + bch, 'd', nil).
AddItem("Cardano (ADA)", "\u20B9 " + ada, 'e', nil).
AddItem("Litecoin (LTC)", "\u20B9 " + ltc, 'b', nil).
AddItem("Quit", "Press to exit", 'q', func() {
app.Stop()
})
if err := app.SetRoot(list, true).SetFocus(list).Run(); err != nil {
panic(err)
}
}