-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (33 loc) · 794 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/leekchan/accounting"
)
func main() {
doc, err := goquery.NewDocument("https://ptax.bcb.gov.br/ptax_internet/consultarUltimaCotacaoDolar.do")
if err != nil {
log.Fatal(err)
os.Exit(1)
}
result := doc.Find(".fundoPadraoBClaro2 td[align=right]")
value, err := strconv.ParseFloat(strings.Replace(result.First().Text(), ",", ".", -1), 64)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
ac := accounting.Accounting{Symbol: "R$ ", Precision: 2, Thousand: ".", Decimal: ","}
if len(os.Args) > 1 {
reais, err := strconv.ParseFloat(os.Args[1], 64)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
value = value * reais
}
fmt.Println(ac.FormatMoney(value))
}