-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (48 loc) · 1.45 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
package main
import (
"flag"
"fmt"
"os"
"strings"
"time"
"github.com/uelei/brl-rate-get/pkg"
)
func handle_get(currency string) {
yesterday := brlrateget.GenerateYesterdayString()
currentTime := time.Now()
currency = strings.ToUpper(currency)
rates := brlrateget.MakeRangeRequest(yesterday, currentTime, currency, false)
brlrateget.FormatGetResult(rates, currency)
}
func handle_range(args []string) {
if len(args) < 3 {
fmt.Println("You must pass a currency, start_date and a end_date after the command")
fmt.Println(" brl-rate-get -range usd 2023-10-01 2023-10-31")
os.Exit(0)
}
start_date := brlrateget.ParseStringToDate(args[1])
end_date := brlrateget.ParseStringToDate(args[2])
currency := args[0]
rates := brlrateget.MakeRangeRequest(start_date, end_date, strings.ToUpper(currency), true)
filename := fmt.Sprintf("%s_brl_%s-%s.csv", currency,
start_date.Format("2006-01-02"), end_date.Format("2006-01-02"))
brlrateget.WriteResultsToCSV(rates, filename)
fmt.Println("File saved ", filename)
}
func main() {
getCmd := flag.Bool("get", false, "To get yesterday closing currency")
rangeCmd := flag.Bool("range", false, "To get a range of closing currency rates")
flag.Parse()
if len(flag.Args()) < 1 {
fmt.Println("You must pass a currency after the command")
os.Exit(0)
}
switch {
case *rangeCmd:
handle_range(flag.Args())
case *getCmd:
handle_get(flag.Args()[0])
default:
fmt.Println("You must pass a command")
}
}