Skip to content

Commit 7c3abf5

Browse files
committed
Adds formatting for strings returned as html, ignores cert errors.
1 parent b51dc15 commit 7c3abf5

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
*.exe
1010
qtrn
1111
.DS_Store
12+
dist/

cli/equity.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ func topOfBook(equities []*finance.Equity) (data [][]string) {
101101
toString(e.AskSize),
102102
toStringF(e.RegularMarketOpen),
103103
toStringF(e.RegularMarketPreviousClose),
104-
e.LongName,
104+
parseString(e.LongName),
105105
})
106+
106107
}
107108
return
108109
}
@@ -115,7 +116,7 @@ func full(equities []*finance.Equity) (data [][]string) {
115116
change := fmt.Sprintf("%s%s [%s%%]", getPrefix(e), toStringF(e.Quote.RegularMarketChange), toStringF(e.RegularMarketChangePercent))
116117
data = append(data,
117118
[]string{"Symbol", e.Symbol},
118-
[]string{"Company", e.LongName},
119+
[]string{"Company", parseString(e.LongName)},
119120
[]string{"Time", timestamp},
120121
[]string{"Last", toStringF(e.RegularMarketPrice)},
121122
[]string{"Change", change},

cli/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
package cli
1616

1717
import (
18+
"crypto/tls"
1819
"fmt"
20+
"net/http"
1921
"os"
2022

23+
finance "github.com/piquette/finance-go"
2124
"github.com/piquette/qtrn/version"
2225
"github.com/spf13/cobra"
2326
)
@@ -39,11 +42,17 @@ var (
3942
)
4043

4144
func init() {
45+
//
46+
tr := &http.Transport{
47+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
48+
}
49+
client := &http.Client{Transport: tr}
50+
finance.SetHTTPClient(client)
51+
4252
// cmdQtrn.AddCommand(chartCmd)
4353
// cmdQtrn.AddCommand(writeCmd)
4454
cmdQtrn.AddCommand(equityCmd)
4555
cmdQtrn.Flags().BoolVarP(&flagPrintVersion, "version", "v", false, "show the version and exit")
46-
4756
}
4857

4958
// MainFunc adds all child commands to the root command sets flags appropriately.

cli/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cli
1616

1717
import (
1818
"fmt"
19+
"html"
1920
"strconv"
2021
"strings"
2122
"time"
@@ -37,6 +38,13 @@ func getPrefix(e *finance.Equity) string {
3738
return " "
3839
}
3940

41+
// parseString formats weird html strings.
42+
func parseString(s string) string {
43+
s = strings.Replace(s, " ", "", -1)
44+
return html.UnescapeString(s)
45+
}
46+
47+
// getFormattedDate returns a formatted date string from an equity.
4048
func getFormattedDate(e *finance.Equity) string {
4149
stamp := e.Quote.RegularMarketTime
4250
dt := time.Unix(int64(stamp), 0)

0 commit comments

Comments
 (0)