Skip to content

Commit

Permalink
Update go version, CLI, miscellaneous bugs (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3an authored Feb 22, 2022
1 parent 1fe6d98 commit c781b63
Show file tree
Hide file tree
Showing 28 changed files with 4,274 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.15.8
1.17.7
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ linters:
- rowserrcheck
- exportloopref
- staticcheck
- structcheck
# - structcheck
- typecheck
- unconvert
- unparam
- unused
# - unused
- varcheck
- whitespace

Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fail_fast: true
repos:
- repo: git://github.com/dnephin/pre-commit-golang
rev: master
rev: v0.5.0
hooks:
- id: go-fmt
- id: go-mod-tidy
Expand All @@ -14,10 +14,10 @@ repos:
- id: no-go-testing
- id: golangci-lint
# - id: go-critic
- id: go-unit-tests
# - id: go-unit-tests
- id: go-build
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v0.7.1
rev: v4.1.0
hooks:
- id: check-merge-conflict
- id: check-yaml
Expand Down
4 changes: 2 additions & 2 deletions calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package calendar

import (
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"strconv"
Expand Down Expand Up @@ -83,7 +83,7 @@ func (c *Client) GetCalendar() (*dataframe.DataFrame, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion calendar/calendar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
"github.com/stretchr/testify/require"

"github.com/d3an/finviz/utils"
"github.com/d3an/finviz/utils/test"
)

func newTestClient(config *Config) *Client {
if config != nil {
return &Client{
Client: &http.Client{
Timeout: 30 * time.Second,
Transport: utils.AddHeaderTransport(config.recorder),
Transport: test.AddHeaderTransport(config.recorder),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions earnings/earnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package earnings

import (
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -81,7 +81,7 @@ func (c *Client) GetEarnings() (*dataframe.DataFrame, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion earnings/earnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
"github.com/stretchr/testify/require"

"github.com/d3an/finviz/utils"
"github.com/d3an/finviz/utils/test"
)

func newTestClient(config *Config) *Client {
if config != nil {
return &Client{
Client: &http.Client{
Timeout: 30 * time.Second,
Transport: utils.AddHeaderTransport(config.recorder),
Transport: test.AddHeaderTransport(config.recorder),
},
}
}
Expand Down
27 changes: 7 additions & 20 deletions finviz/cmd/calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,29 @@ import (
)

var (
outputCSVArg string
outputJSONArg string
outFile string

// Cmd is the CLI subcommand for FinViz news
// Cmd is the CLI subcommand for Finviz news
Cmd = &cobra.Command{
Use: "calendar",
Aliases: []string{"cal", "ec"},
Short: "Finviz Economic Calendar.",
Short: "Finviz Economic Calendar",
Long: "Finviz Economic Calendar returns this week's Economic Calendar.",
Run: func(cmd *cobra.Command, args []string) {
var err error

client := calendar.New(nil)
df, err := client.GetCalendar()
if err != nil {
utils.Err(err)
}

if outputCSVArg != "" {
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
utils.Err(err)
}
} else if outputJSONArg != "" {
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
utils.Err(err)
}
} else {
utils.PrintFullDataFrame(df)
if err = utils.ExportData(df, outFile); err != nil {
utils.Err(err)
}
},
}
)

func init() {
// --output-csv data.csv
// --output-json data.json
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
// -o <filename>
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
}
27 changes: 7 additions & 20 deletions finviz/cmd/earnings/earnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,29 @@ import (
)

var (
outputCSVArg string
outputJSONArg string
outFile string

// Cmd is the CLI subcommand for FinViz news
// Cmd is the CLI subcommand for Finviz news
Cmd = &cobra.Command{
Use: "earnings",
Aliases: []string{"e"},
Short: "Finviz Earnings.",
Short: "Finviz Earnings",
Long: "Finviz Earnings returns the tickers with earnings releases left this week.",
Run: func(cmd *cobra.Command, args []string) {
var err error

client := earnings.New(nil)
df, err := client.GetEarnings()
if err != nil {
utils.Err(err)
}

if outputCSVArg != "" {
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
utils.Err(err)
}
} else if outputJSONArg != "" {
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
utils.Err(err)
}
} else {
utils.PrintFullDataFrame(df)
if err = utils.ExportData(df, outFile); err != nil {
utils.Err(err)
}
},
}
)

func init() {
// --output-csv data.csv
// --output-json data.json
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
// -o <filename>
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
}
38 changes: 13 additions & 25 deletions finviz/cmd/news/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,33 @@ import (
)

var (
outputCSVArg string
outputJSONArg string
viewArg string
outFile string
view *utils.Enum

// Cmd is the CLI subcommand for FinViz news
// Cmd is the CLI subcommand for Finviz news
Cmd = &cobra.Command{
Use: "news",
Aliases: []string{"ns"},
Short: "FinViz News.",
Long: "FinViz News returns the latest news.",
Short: "Finviz News",
Long: "Finviz News returns the latest news.",
Run: func(cmd *cobra.Command, args []string) {
var err error

client := news.New(nil)
df, err := client.GetNews(viewArg)
df, err := client.GetNews(view.Value)
if err != nil {
utils.Err(err)
}

if outputCSVArg != "" {
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
utils.Err(err)
}
} else if outputJSONArg != "" {
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
utils.Err(err)
}
} else {
utils.PrintFullDataFrame(df)
if err = utils.ExportData(df, outFile); err != nil {
utils.Err(err)
}
},
}
)

func init() {
// -v 1
// --output-csv data.csv
// --output-json data.json
Cmd.Flags().StringVarP(&viewArg, "view", "v", "1", "2")
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
// -v time|source
// -o <filename>
view = utils.NewEnum([]string{"time", "source"}, "time")
Cmd.Flags().VarP(view, "view", "v", "time|source")
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
}
37 changes: 12 additions & 25 deletions finviz/cmd/quote/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,32 @@ import (
)

var (
outputCSVArg string
outputJSONArg string
tickerArgs []string
outFile string
tickers []string

// Cmd is the CLI subcommand for FinViz news
// Cmd is the CLI subcommand for Finviz news
Cmd = &cobra.Command{
Use: "quote",
Aliases: []string{"q", "quotes"},
Short: "FinViz Quotes.",
Long: "FinViz Quotes returns the quotes for tickers provided.",
Short: "Finviz Quotes",
Long: "Finviz Quotes returns the quotes for tickers provided.",
Run: func(cmd *cobra.Command, args []string) {
var err error

client := quote.New(nil)
results, err := client.GetQuotes(tickerArgs)
results, err := client.GetQuotes(tickers)
if err != nil {
utils.Err(err)
}

if outputCSVArg != "" {
if err := utils.ExportCSV(results.Data, outputCSVArg); err != nil {
utils.Err(err)
}
} else if outputJSONArg != "" {
if err := utils.ExportJSON(results.Data, outputJSONArg); err != nil {
utils.Err(err)
}
} else {
utils.PrintFullDataFrame(results.Data)
if err = utils.ExportData(results.Data, outFile); err != nil {
utils.Err(err)
}
},
}
)

func init() {
// -v 1
// --output-csv data.csv
// --output-json data.json
Cmd.Flags().StringSliceVarP(&tickerArgs, "tickers", "t", nil, "AAPL,GS,amzn")
Cmd.Flags().StringVar(&outputCSVArg, "output-csv", "", "outputFileName.csv")
Cmd.Flags().StringVar(&outputJSONArg, "output-json", "", "outputFileName.json")
// -t aapl,amzn,tsla
// -o <filename>
Cmd.Flags().StringSliceVarP(&tickers, "tickers", "t", nil, "AAPL,GS,amzn")
Cmd.Flags().StringVarP(&outFile, "outfile", "o", "", "output.(csv|json)")
}
2 changes: 1 addition & 1 deletion finviz/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var rootCmd = &cobra.Command{
Use: "finviz",
Short: "This is an unofficial CLI for FinViz.com",
Short: "This is an unofficial CLI for Finviz.com",
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
fmt.Println("Error: ", err)
Expand Down
30 changes: 8 additions & 22 deletions finviz/cmd/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,33 @@ import (
)

var (
url string
outputCSVArg string
outputJSONArg string
outFile string

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

client := New(nil)
df, err := client.GetScreenerResults(url)
df, err := client.GetScreenerResults(args[0])
if err != nil {
utils.Err(err)
}

if outputCSVArg != "" {
if err := utils.ExportCSV(df, outputCSVArg); err != nil {
utils.Err(err)
}
} else if outputJSONArg != "" {
if err := utils.ExportJSON(df, outputJSONArg); err != nil {
utils.Err(err)
}
} else {
utils.PrintFullDataFrame(df)
if err = utils.ExportData(df, outFile); err != nil {
utils.Err(err)
}
},
}
)

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

0 comments on commit c781b63

Please sign in to comment.