Skip to content

Commit 1738e14

Browse files
committed
Fixing code.
1 parent a6170b3 commit 1738e14

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/anaskhan96/soup"
10+
log "github.com/sirupsen/logrus"
1011
)
1112

1213
func parseProduct(result soup.Root) {
@@ -17,20 +18,23 @@ func parseProduct(result soup.Root) {
1718
product.Image = result.Find("img", "class", "s-access-image").Attrs()["src"]
1819
product.Price = result.Find("span", "class", "s-price").Text()
1920

20-
product.GetReviews()
21+
if string([]rune(product.Link)[0]) != "/" {
22+
product.GetReviews()
23+
}
2124

2225
json.NewEncoder(os.Stdout).Encode(product)
2326
}
2427

2528
func main() {
2629
now := time.Now().UTC()
2730

28-
resp, err := soup.Get("https://www.amazon.in/b/?_encoding=UTF8&node=1389401031&ref_=sv_top_elec_mega_1")
31+
resp, err := soup.Get("https://www.amazon.in/TVs/b/ref=nav_shopall_sbc_tvelec_television?ie=UTF8&node=1389396031")
2932

3033
// fmt.Println("Main fetch time: ", time.Since(now))
3134
// now = time.Now().UTC()
3235

3336
if err != nil {
37+
log.Error("Encountered error: ", err)
3438
os.Exit(1)
3539
}
3640

product.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package main
22

33
import (
4-
"os"
5-
64
"github.com/anaskhan96/soup"
5+
log "github.com/sirupsen/logrus"
76
)
87

98
// A Product represents a product on amazon
@@ -24,7 +23,8 @@ func (product *Product) GetReviews() {
2423
// now = time.Now().UTC()
2524

2625
if err != nil {
27-
os.Exit(1)
26+
log.Error("Encountered error {%s} while vising: %#v", err, product)
27+
return
2828
}
2929

3030
doc := soup.HTMLParse(resp)

0 commit comments

Comments
 (0)