Skip to content

Commit

Permalink
go linted go fmted
Browse files Browse the repository at this point in the history
  • Loading branch information
diptomondal007 committed Apr 24, 2021
1 parent 003cf1d commit 3864e0a
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 91 deletions.
62 changes: 33 additions & 29 deletions cse.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,25 @@ type report struct {
ReportPDFLink string
}

// Company ...
type Company struct {
CompanyName string
TradingCode string
}

// CompanyListingByIndustry ...
type CompanyListingByIndustry struct {
IndustryType string
List []*Company
}

// CompanyListingByCategory ...
type CompanyListingByCategory struct {
Category string
List []*Company
}

// PriceEarningRatios ...
type PriceEarningRatios struct {
Date string
PriceEarningRatioArray []*PriceEarningRatio
Expand Down Expand Up @@ -617,8 +621,8 @@ func (c *CSE) GetPriceEarningRatio(day, month, year string) (*PriceEarningRatios
priceEarningRatioArray := make([]*PriceEarningRatio, 0)

data := fmt.Sprintf("pe_date=%s-%s-%s", year, month, day)
data_body := strings.NewReader(data)
req, err := http.NewRequest("POST", "https://www.cse.com.bd/market/pe_ratio", data_body)
dataBody := strings.NewReader(data)
req, err := http.NewRequest("POST", "https://www.cse.com.bd/market/pe_ratio", dataBody)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -675,44 +679,44 @@ func (c *CSE) GetPriceEarningRatio(day, month, year string) (*PriceEarningRatios
for _, v := range tabsContents {
if htmlquery.SelectAttr(v, "class") == "pe_ratio_tabs_cont" {
isDataFound = true
pe_ratiocont_1 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_1"]`)
pe_ratiocont_2 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_2"]`)
pe_ratiocont_3_td1 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_3"]/table/tbody/tr/td[1]`)
pe_ratiocont_3_td2 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_3"]/table/tbody/tr/td[2]`)
peRatiocont1 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_1"]`)
peRatiocont2 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_2"]`)
peRatiocont3Td1 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_3"]/table/tbody/tr/td[1]`)
peRatiocont3Td2 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_3"]/table/tbody/tr/td[2]`)
//log.Println(htmlquery.InnerText(pe_ratiocont_3_td1), htmlquery.InnerText(pe_ratiocont_3_td2))
pe_ratiocont_4_td1 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_4"]/table/tbody/tr/td[1]`)
pe_ratiocont_4_td2 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_4"]/table/tbody/tr/td[2]`)
pe_ratiocont_4_td3 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_4"]/table/tbody/tr/td[3]`)
pe_ratiocont_5 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_5"]`)
pe_ratiocont_6 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_6"]`)
pe_ratiocont_7 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_7"]`)
pe_ratiocont_8 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_8"]`)
pe_ratiocont_9 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_9"]`)
peRatiocont4Rd1 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_4"]/table/tbody/tr/td[1]`)
peRatiocont4Td2 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_4"]/table/tbody/tr/td[2]`)
peRatiocont4Td3 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_4"]/table/tbody/tr/td[3]`)
peRatiocont5 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_5"]`)
peRatiocont6 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_6"]`)
peRatiocont7 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_7"]`)
peRatiocont8 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_8"]`)
peRatiocont9 := htmlquery.FindOne(v, `//*[@id="pe_ratiocont_9"]`)

priceEarningRatio := &PriceEarningRatio{
SL: strings.Replace(htmlquery.InnerText(pe_ratiocont_1), ".", "", -1),
TradingCode: htmlquery.InnerText(pe_ratiocont_2),
SL: strings.Replace(htmlquery.InnerText(peRatiocont1), ".", "", -1),
TradingCode: htmlquery.InnerText(peRatiocont2),
FinancialYear: struct {
From string
To string
}{
From: htmlquery.InnerText(pe_ratiocont_3_td1),
To: htmlquery.InnerText(pe_ratiocont_3_td2),
From: htmlquery.InnerText(peRatiocont3Td1),
To: htmlquery.InnerText(peRatiocont3Td2),
},
EPSAsPerUpdatedUnAuditedAccounts: struct {
Quarter1 float64
HalfYear float64
Quarter3 float64
}{
Quarter1: toFloat64(htmlquery.InnerText(pe_ratiocont_4_td1)),
HalfYear: toFloat64(htmlquery.InnerText(pe_ratiocont_4_td2)),
Quarter3: toFloat64(htmlquery.InnerText(pe_ratiocont_4_td3)),
Quarter1: toFloat64(htmlquery.InnerText(peRatiocont4Rd1)),
HalfYear: toFloat64(htmlquery.InnerText(peRatiocont4Td2)),
Quarter3: toFloat64(htmlquery.InnerText(peRatiocont4Td3)),
},
AnnualizedEPS: toFloat64(htmlquery.InnerText(pe_ratiocont_5)),
EPSBasedOnLastAuditedAccounts: toFloat64(htmlquery.InnerText(pe_ratiocont_6)),
ClosePrice: toFloat64(htmlquery.InnerText(pe_ratiocont_7)),
PERatioBasedOnAnnualizedEPS: toFloat64(htmlquery.InnerText(pe_ratiocont_8)),
PERatioBasedOnLastAuditedAccounts: toFloat64(htmlquery.InnerText(pe_ratiocont_9)),
AnnualizedEPS: toFloat64(htmlquery.InnerText(peRatiocont5)),
EPSBasedOnLastAuditedAccounts: toFloat64(htmlquery.InnerText(peRatiocont6)),
ClosePrice: toFloat64(htmlquery.InnerText(peRatiocont7)),
PERatioBasedOnAnnualizedEPS: toFloat64(htmlquery.InnerText(peRatiocont8)),
PERatioBasedOnLastAuditedAccounts: toFloat64(htmlquery.InnerText(peRatiocont9)),
}

priceEarningRatioArray = append(priceEarningRatioArray, priceEarningRatio)
Expand All @@ -721,7 +725,7 @@ func (c *CSE) GetPriceEarningRatio(day, month, year string) (*PriceEarningRatios
}

}
if !isDataFound{
if !isDataFound {
return nil, errNoDataFound
}

Expand All @@ -733,11 +737,11 @@ func (c *CSE) GetPriceEarningRatio(day, month, year string) (*PriceEarningRatios

// CseMarketStatus holds the data for if market is open/close
type CseMarketStatus struct {
IsOpen bool
IsOpen bool
}

// GetMarketStatus returns the CseMarketStatus with is open/close
func (d *CSE) GetMarketStatus() (*CseMarketStatus, error) {
func (c *CSE) GetMarketStatus() (*CseMarketStatus, error) {
doc, err := htmlquery.LoadURL("https://www.cse.com.bd/market/current_price")
if err != nil {
return nil, err
Expand Down
40 changes: 20 additions & 20 deletions cse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestNewCSE(t *testing.T) {
want *CSE
}{
// TODO: Add test cases.
{"new",new(CSE)},
{"new", new(CSE)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func Test_getCSELatestPrices(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"", make([]*CSEShare,329), false},
{"", make([]*CSEShare, 329), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestCSE_GetLatestPrices(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"", NewCSE() ,args{SortByHighPrice, ASC}, make([]*CSEShare,329), false},
{"", NewCSE(), args{SortByHighPrice, ASC}, make([]*CSEShare, 329), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -88,23 +88,23 @@ func Test_sortCse(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"", args{make([]*CSEShare,0), SortByTradingCode, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByTradingCode, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByHighPrice, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByHighPrice, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByLowPrice, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByLowPrice, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByLTP, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByLTP, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByNumberOfTrades, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByNumberOfTrades, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByYCP, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByYCP, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByValue, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByValue, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByVolumeOfShare, ASC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByVolumeOfShare, DESC}, make([]*CSEShare,0), false},
{"", args{make([]*CSEShare,0), SortByPercentageChange, DESC}, nil, true},
{"", args{make([]*CSEShare, 0), SortByTradingCode, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByTradingCode, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByHighPrice, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByHighPrice, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByLowPrice, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByLowPrice, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByLTP, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByLTP, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByNumberOfTrades, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByNumberOfTrades, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByYCP, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByYCP, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByValue, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByValue, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByVolumeOfShare, ASC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByVolumeOfShare, DESC}, make([]*CSEShare, 0), false},
{"", args{make([]*CSEShare, 0), SortByPercentageChange, DESC}, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
15 changes: 7 additions & 8 deletions dse.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func getDSELatestPrices(url string) ([]*DSEShare, error) {
if url == "" {
url = "https://www.dsebd.org/latest_share_price_scroll_l.php"
}
doc, err := htmlquery.LoadURL("https://www.dsebd.org/latest_share_price_scroll_l.php")
doc, err := htmlquery.LoadURL(url)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -407,7 +407,7 @@ type MarketSummary struct {
DSESIndexChangePercentage float64 `json:"dses_index_change_percentage"`
} `json:"dses"`

TotalTrade int64 `json:""`
TotalTrade int64 `json:""`
TotalValueInMN float64 `json:""`
TotalVolume int64 `json:""`

Expand Down Expand Up @@ -467,7 +467,7 @@ func (d *DSE) GetMarketSummary() (*MarketSummary, error) {
dseMarketSummary.DseX.DSEXIndexChange = dsexIndexChange
case 4:
dsexIndexChangePString := htmlquery.InnerText(v)
dsexIndexChangeP, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(dsexIndexChangePString,"%","",-1)) , 64)
dsexIndexChangeP, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(dsexIndexChangePString, "%", "", -1)), 64)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -503,15 +503,14 @@ func (d *DSE) GetMarketSummary() (*MarketSummary, error) {
dseMarketSummary.DseS.DSESIndexChange = dsesIndexChange
case 4:
dsesIndexChangePString := htmlquery.InnerText(v)
dsesIndexChangeP, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(dsesIndexChangePString,"%","",-1)) , 64)
dsesIndexChangeP, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(dsesIndexChangePString, "%", "", -1)), 64)
if err != nil {
return nil, err
}
dseMarketSummary.DseS.DSESIndexChangePercentage = dsesIndexChangeP
}
}


// DS30
node, err = htmlquery.Query(doc, `/html/body/div[2]/section/div/div[1]/div/div[3]`)
if err != nil {
Expand Down Expand Up @@ -540,7 +539,7 @@ func (d *DSE) GetMarketSummary() (*MarketSummary, error) {
dseMarketSummary.Ds30.DS30IndexChange = ds30IndexChange
case 4:
ds30IndexChangePString := htmlquery.InnerText(v)
ds30IndexChangeP, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(ds30IndexChangePString,"%","",-1)) , 64)
ds30IndexChangeP, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(ds30IndexChangePString, "%", "", -1)), 64)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -576,7 +575,7 @@ func (d *DSE) GetMarketSummary() (*MarketSummary, error) {
dseMarketSummary.TotalVolume = totalVolume
case 3:
totalValueString := htmlquery.InnerText(v)
totalValue, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(totalValueString,"%","",-1)) , 64)
totalValue, err := strconv.ParseFloat(strings.TrimSpace(strings.Replace(totalValueString, "%", "", -1)), 64)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -612,7 +611,7 @@ func (d *DSE) GetMarketSummary() (*MarketSummary, error) {
dseMarketSummary.IssuesDeclined = int32(issuesDeclined)
case 3:
issuesUnchangedString := htmlquery.InnerText(v)
issuesUnchanged, err := strconv.ParseInt(strings.TrimSpace(strings.Replace(issuesUnchangedString,"%","",-1)), 10, 64)
issuesUnchanged, err := strconv.ParseInt(strings.TrimSpace(strings.Replace(issuesUnchangedString, "%", "", -1)), 10, 64)
if err != nil {
return nil, err
}
Expand Down
47 changes: 23 additions & 24 deletions dse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestNewDSE(t *testing.T) {
want *DSE
}{
// TODO: Add test cases.
{"new",new(DSE)},
{"new", new(DSE)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -33,7 +33,7 @@ func Test_getDSELatestPrices(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"",args{""}, make([]*DSEShare,359), false},
{"", args{""}, make([]*DSEShare, 359), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestDSE_GetLatestPricesByCategory(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"", NewDSE() ,args{"A", SortByHighPrice, ASC}, make([]*DSEShare,258), false},
{"", NewDSE(), args{"A", SortByHighPrice, ASC}, make([]*DSEShare, 258), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestDSE_GetLatestPrices(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"", NewDSE() ,args{SortByHighPrice, ASC}, make([]*DSEShare,359), false},
{"", NewDSE(), args{SortByHighPrice, ASC}, make([]*DSEShare, 359), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -123,26 +123,25 @@ func Test_sortDse(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{"", args{make([]*DSEShare,0), SortByTradingCode, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByTradingCode, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByHighPrice, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByHighPrice, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByLowPrice, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByLowPrice, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByLTP, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByLTP, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByNumberOfTrades, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByNumberOfTrades, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByPriceChange, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByPriceChange, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByYCP, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByYCP, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByValue, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByValue, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByVolumeOfShare, ASC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByVolumeOfShare, DESC}, make([]*DSEShare,0), false},
{"", args{make([]*DSEShare,0), SortByPercentageChange, DESC}, nil, true},

{"", args{make([]*DSEShare, 0), SortByTradingCode, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByTradingCode, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByHighPrice, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByHighPrice, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByLowPrice, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByLowPrice, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByLTP, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByLTP, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByNumberOfTrades, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByNumberOfTrades, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByPriceChange, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByPriceChange, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByYCP, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByYCP, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByValue, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByValue, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByVolumeOfShare, ASC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByVolumeOfShare, DESC}, make([]*DSEShare, 0), false},
{"", args{make([]*DSEShare, 0), SortByPercentageChange, DESC}, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 3864e0a

Please sign in to comment.