Skip to content

Commit

Permalink
Adds formatting for strings returned as html, ignores cert errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ackleymi committed Jun 26, 2018
1 parent b51dc15 commit 7c3abf5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
*.exe
qtrn
.DS_Store
dist/
5 changes: 3 additions & 2 deletions cli/equity.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ func topOfBook(equities []*finance.Equity) (data [][]string) {
toString(e.AskSize),
toStringF(e.RegularMarketOpen),
toStringF(e.RegularMarketPreviousClose),
e.LongName,
parseString(e.LongName),
})

}
return
}
Expand All @@ -115,7 +116,7 @@ func full(equities []*finance.Equity) (data [][]string) {
change := fmt.Sprintf("%s%s [%s%%]", getPrefix(e), toStringF(e.Quote.RegularMarketChange), toStringF(e.RegularMarketChangePercent))
data = append(data,
[]string{"Symbol", e.Symbol},
[]string{"Company", e.LongName},
[]string{"Company", parseString(e.LongName)},
[]string{"Time", timestamp},
[]string{"Last", toStringF(e.RegularMarketPrice)},
[]string{"Change", change},
Expand Down
11 changes: 10 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package cli

import (
"crypto/tls"
"fmt"
"net/http"
"os"

finance "github.com/piquette/finance-go"
"github.com/piquette/qtrn/version"
"github.com/spf13/cobra"
)
Expand All @@ -39,11 +42,17 @@ var (
)

func init() {
//
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
finance.SetHTTPClient(client)

// cmdQtrn.AddCommand(chartCmd)
// cmdQtrn.AddCommand(writeCmd)
cmdQtrn.AddCommand(equityCmd)
cmdQtrn.Flags().BoolVarP(&flagPrintVersion, "version", "v", false, "show the version and exit")

}

// MainFunc adds all child commands to the root command sets flags appropriately.
Expand Down
8 changes: 8 additions & 0 deletions cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cli

import (
"fmt"
"html"
"strconv"
"strings"
"time"
Expand All @@ -37,6 +38,13 @@ func getPrefix(e *finance.Equity) string {
return " "
}

// parseString formats weird html strings.
func parseString(s string) string {
s = strings.Replace(s, " ", "", -1)
return html.UnescapeString(s)
}

// getFormattedDate returns a formatted date string from an equity.
func getFormattedDate(e *finance.Equity) string {
stamp := e.Quote.RegularMarketTime
dt := time.Unix(int64(stamp), 0)
Expand Down

0 comments on commit 7c3abf5

Please sign in to comment.