Skip to content

Commit c781b63

Browse files
authored
Update go version, CLI, miscellaneous bugs (#87)
1 parent 1fe6d98 commit c781b63

28 files changed

+4274
-215
lines changed

.go-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.15.8
1+
1.17.7

.golangci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ linters:
9292
- rowserrcheck
9393
- exportloopref
9494
- staticcheck
95-
- structcheck
95+
# - structcheck
9696
- typecheck
9797
- unconvert
9898
- unparam
99-
- unused
99+
# - unused
100100
- varcheck
101101
- whitespace
102102

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fail_fast: true
66
repos:
77
- repo: git://github.com/dnephin/pre-commit-golang
8-
rev: master
8+
rev: v0.5.0
99
hooks:
1010
- id: go-fmt
1111
- id: go-mod-tidy
@@ -14,10 +14,10 @@ repos:
1414
- id: no-go-testing
1515
- id: golangci-lint
1616
# - id: go-critic
17-
- id: go-unit-tests
17+
# - id: go-unit-tests
1818
- id: go-build
1919
- repo: git://github.com/pre-commit/pre-commit-hooks
20-
rev: v0.7.1
20+
rev: v4.1.0
2121
hooks:
2222
- id: check-merge-conflict
2323
- id: check-yaml

calendar/calendar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package calendar
77

88
import (
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net"
1212
"net/http"
1313
"strconv"
@@ -83,7 +83,7 @@ func (c *Client) GetCalendar() (*dataframe.DataFrame, error) {
8383
}
8484
defer resp.Body.Close()
8585

86-
body, err := ioutil.ReadAll(resp.Body)
86+
body, err := io.ReadAll(resp.Body)
8787
if err != nil {
8888
return nil, err
8989
}

calendar/calendar_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616
"github.com/stretchr/testify/require"
1717

1818
"github.com/d3an/finviz/utils"
19+
"github.com/d3an/finviz/utils/test"
1920
)
2021

2122
func newTestClient(config *Config) *Client {
2223
if config != nil {
2324
return &Client{
2425
Client: &http.Client{
2526
Timeout: 30 * time.Second,
26-
Transport: utils.AddHeaderTransport(config.recorder),
27+
Transport: test.AddHeaderTransport(config.recorder),
2728
},
2829
}
2930
}

earnings/earnings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package earnings
77

88
import (
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net"
1212
"net/http"
1313
"sync"
@@ -81,7 +81,7 @@ func (c *Client) GetEarnings() (*dataframe.DataFrame, error) {
8181
}
8282
defer resp.Body.Close()
8383

84-
body, err := ioutil.ReadAll(resp.Body)
84+
body, err := io.ReadAll(resp.Body)
8585
if err != nil {
8686
return nil, err
8787
}

earnings/earnings_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616
"github.com/stretchr/testify/require"
1717

1818
"github.com/d3an/finviz/utils"
19+
"github.com/d3an/finviz/utils/test"
1920
)
2021

2122
func newTestClient(config *Config) *Client {
2223
if config != nil {
2324
return &Client{
2425
Client: &http.Client{
2526
Timeout: 30 * time.Second,
26-
Transport: utils.AddHeaderTransport(config.recorder),
27+
Transport: test.AddHeaderTransport(config.recorder),
2728
},
2829
}
2930
}

finviz/cmd/calendar/calendar.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,29 @@ import (
1313
)
1414

1515
var (
16-
outputCSVArg string
17-
outputJSONArg string
16+
outFile string
1817

19-
// Cmd is the CLI subcommand for FinViz news
18+
// Cmd is the CLI subcommand for Finviz news
2019
Cmd = &cobra.Command{
2120
Use: "calendar",
2221
Aliases: []string{"cal", "ec"},
23-
Short: "Finviz Economic Calendar.",
22+
Short: "Finviz Economic Calendar",
2423
Long: "Finviz Economic Calendar returns this week's Economic Calendar.",
2524
Run: func(cmd *cobra.Command, args []string) {
26-
var err error
27-
2825
client := calendar.New(nil)
2926
df, err := client.GetCalendar()
3027
if err != nil {
3128
utils.Err(err)
3229
}
3330

34-
if outputCSVArg != "" {
35-
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
36-
utils.Err(err)
37-
}
38-
} else if outputJSONArg != "" {
39-
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
40-
utils.Err(err)
41-
}
42-
} else {
43-
utils.PrintFullDataFrame(df)
31+
if err = utils.ExportData(df, outFile); err != nil {
32+
utils.Err(err)
4433
}
4534
},
4635
}
4736
)
4837

4938
func init() {
50-
// --output-csv data.csv
51-
// --output-json data.json
52-
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
53-
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
39+
// -o <filename>
40+
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
5441
}

finviz/cmd/earnings/earnings.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,29 @@ import (
1313
)
1414

1515
var (
16-
outputCSVArg string
17-
outputJSONArg string
16+
outFile string
1817

19-
// Cmd is the CLI subcommand for FinViz news
18+
// Cmd is the CLI subcommand for Finviz news
2019
Cmd = &cobra.Command{
2120
Use: "earnings",
2221
Aliases: []string{"e"},
23-
Short: "Finviz Earnings.",
22+
Short: "Finviz Earnings",
2423
Long: "Finviz Earnings returns the tickers with earnings releases left this week.",
2524
Run: func(cmd *cobra.Command, args []string) {
26-
var err error
27-
2825
client := earnings.New(nil)
2926
df, err := client.GetEarnings()
3027
if err != nil {
3128
utils.Err(err)
3229
}
3330

34-
if outputCSVArg != "" {
35-
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
36-
utils.Err(err)
37-
}
38-
} else if outputJSONArg != "" {
39-
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
40-
utils.Err(err)
41-
}
42-
} else {
43-
utils.PrintFullDataFrame(df)
31+
if err = utils.ExportData(df, outFile); err != nil {
32+
utils.Err(err)
4433
}
4534
},
4635
}
4736
)
4837

4938
func init() {
50-
// --output-csv data.csv
51-
// --output-json data.json
52-
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
53-
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
39+
// -o <filename>
40+
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
5441
}

finviz/cmd/news/news.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,33 @@ import (
1313
)
1414

1515
var (
16-
outputCSVArg string
17-
outputJSONArg string
18-
viewArg string
16+
outFile string
17+
view *utils.Enum
1918

20-
// Cmd is the CLI subcommand for FinViz news
19+
// Cmd is the CLI subcommand for Finviz news
2120
Cmd = &cobra.Command{
2221
Use: "news",
2322
Aliases: []string{"ns"},
24-
Short: "FinViz News.",
25-
Long: "FinViz News returns the latest news.",
23+
Short: "Finviz News",
24+
Long: "Finviz News returns the latest news.",
2625
Run: func(cmd *cobra.Command, args []string) {
27-
var err error
28-
2926
client := news.New(nil)
30-
df, err := client.GetNews(viewArg)
27+
df, err := client.GetNews(view.Value)
3128
if err != nil {
3229
utils.Err(err)
3330
}
3431

35-
if outputCSVArg != "" {
36-
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
37-
utils.Err(err)
38-
}
39-
} else if outputJSONArg != "" {
40-
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
41-
utils.Err(err)
42-
}
43-
} else {
44-
utils.PrintFullDataFrame(df)
32+
if err = utils.ExportData(df, outFile); err != nil {
33+
utils.Err(err)
4534
}
4635
},
4736
}
4837
)
4938

5039
func init() {
51-
// -v 1
52-
// --output-csv data.csv
53-
// --output-json data.json
54-
Cmd.Flags().StringVarP(&viewArg, "view", "v", "1", "2")
55-
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
56-
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
40+
// -v time|source
41+
// -o <filename>
42+
view = utils.NewEnum([]string{"time", "source"}, "time")
43+
Cmd.Flags().VarP(view, "view", "v", "time|source")
44+
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
5745
}

finviz/cmd/quote/quote.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,32 @@ import (
1313
)
1414

1515
var (
16-
outputCSVArg string
17-
outputJSONArg string
18-
tickerArgs []string
16+
outFile string
17+
tickers []string
1918

20-
// Cmd is the CLI subcommand for FinViz news
19+
// Cmd is the CLI subcommand for Finviz news
2120
Cmd = &cobra.Command{
2221
Use: "quote",
2322
Aliases: []string{"q", "quotes"},
24-
Short: "FinViz Quotes.",
25-
Long: "FinViz Quotes returns the quotes for tickers provided.",
23+
Short: "Finviz Quotes",
24+
Long: "Finviz Quotes returns the quotes for tickers provided.",
2625
Run: func(cmd *cobra.Command, args []string) {
27-
var err error
28-
2926
client := quote.New(nil)
30-
results, err := client.GetQuotes(tickerArgs)
27+
results, err := client.GetQuotes(tickers)
3128
if err != nil {
3229
utils.Err(err)
3330
}
3431

35-
if outputCSVArg != "" {
36-
if err := utils.ExportCSV(results.Data, outputCSVArg); err != nil {
37-
utils.Err(err)
38-
}
39-
} else if outputJSONArg != "" {
40-
if err := utils.ExportJSON(results.Data, outputJSONArg); err != nil {
41-
utils.Err(err)
42-
}
43-
} else {
44-
utils.PrintFullDataFrame(results.Data)
32+
if err = utils.ExportData(results.Data, outFile); err != nil {
33+
utils.Err(err)
4534
}
4635
},
4736
}
4837
)
4938

5039
func init() {
51-
// -v 1
52-
// --output-csv data.csv
53-
// --output-json data.json
54-
Cmd.Flags().StringSliceVarP(&tickerArgs, "tickers", "t", nil, "AAPL,GS,amzn")
55-
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
56-
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
40+
// -t aapl,amzn,tsla
41+
// -o <filename>
42+
Cmd.Flags().StringSliceVarP(&tickers, "tickers", "t", nil, "AAPL,GS,amzn")
43+
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
5744
}

finviz/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
var rootCmd = &cobra.Command{
2222
Use: "finviz",
23-
Short: "This is an unofficial CLI for FinViz.com",
23+
Short: "This is an unofficial CLI for Finviz.com",
2424
Run: func(cmd *cobra.Command, args []string) {
2525
if err := cmd.Help(); err != nil {
2626
fmt.Println("Error: ", err)

finviz/cmd/screener/screener.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,33 @@ import (
1313
)
1414

1515
var (
16-
url string
17-
outputCSVArg string
18-
outputJSONArg string
16+
outFile string
1917

2018
// Cmd is the CLI subcommand for the Screener app
2119
Cmd = &cobra.Command{
2220
Use: "screener <url>",
2321
Aliases: []string{"screen", "scr"},
24-
Short: "FinViz Stock Screener.",
25-
Long: "FinViz Stock Screener searches through large amounts of stock data and returns a list " +
22+
Short: "Finviz Stock Screener",
23+
Long: "Finviz Stock Screener searches through large amounts of stock data and returns a list " +
2624
"of stocks that match one or more selected criteria.",
2725
Run: func(cmd *cobra.Command, args []string) {
28-
if url == "" {
26+
if len(args) == 0 {
2927
utils.Err("URL not provided")
3028
}
3129

3230
client := New(nil)
33-
df, err := client.GetScreenerResults(url)
31+
df, err := client.GetScreenerResults(args[0])
3432
if err != nil {
3533
utils.Err(err)
3634
}
3735

38-
if outputCSVArg != "" {
39-
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
40-
utils.Err(err)
41-
}
42-
} else if outputJSONArg != "" {
43-
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
44-
utils.Err(err)
45-
}
46-
} else {
47-
utils.PrintFullDataFrame(df)
36+
if err = utils.ExportData(df, outFile); err != nil {
37+
utils.Err(err)
4838
}
4939
},
5040
}
5141
)
5242

5343
func init() {
54-
// --output-csv data.csv
55-
// --output-json data.json
56-
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
57-
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
58-
Cmd.Flags().StringVar(&url, "url", "", "https://finviz.com/screener.ashx?v=110&f=exch_nyse")
44+
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
5945
}

0 commit comments

Comments
 (0)