Skip to content

Commit

Permalink
Merge pull request #1 from petersid2022/testing
Browse files Browse the repository at this point in the history
Added features.
  • Loading branch information
petersid2022 committed Mar 18, 2023
2 parents eec44d4 + e654212 commit f155812
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"strings"
"time"
"flag"

"github.com/gocolly/colly"
"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -44,6 +45,10 @@ func link(x string, y string) string {
}

func main() {
startTime := time.Now()

categoryPtr := flag.String("category", "Recommended", "[Recommended], [price_asc], [price_desc], [newest], [pricedrop]")

var productsInfo []productInformation = make([]productInformation, 0, 10)

c := colly.NewCollector()
Expand All @@ -62,7 +67,9 @@ func main() {
productsInfo = append(productsInfo, productInfo)
})

c.Visit("https://www.skroutz.gr/prosfores?order_by=recommended&recent=1")
c.Visit("https://www.skroutz.gr/prosfores?order_by=" + *categoryPtr + "&recent=1")
flag.Parse()
elapsedTime := time.Since(startTime)

rand.Seed(time.Now().UnixNano())
numProductsToPrint := 5
Expand All @@ -77,20 +84,33 @@ func main() {
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetBorder(false)
table.SetRowLine(true)
table.SetCaption(true, "petrside 2023")


for _, i := range indices {
productInfo := productsInfo[i]

out := []string{
strings.TrimSpace(productInfo.name),
strings.TrimSpace(productInfo.oldprice + " €"),
strings.TrimSpace(productInfo.newprice),
link(productInfo.link, "link"),
table.SetCaption(true, "petrside 2023 / Category: " + *categoryPtr + " / Request completed in " + elapsedTime.String())

if *categoryPtr == "Recommended"{
for _, i := range indices {
productInfo := productsInfo[i]

out := []string{
strings.TrimSpace(productInfo.name),
strings.TrimSpace(productInfo.oldprice + " €"),
strings.TrimSpace(productInfo.newprice),
link(productInfo.link, "link"),
}
table.Append(out)
}
table.Render()
} else {
for i := 0; i < len(productsInfo); i++ {
productInfo := productsInfo[i]
out := []string{
strings.TrimSpace(productInfo.name),
strings.TrimSpace(productInfo.oldprice + " €"),
strings.TrimSpace(productInfo.newprice),
link(productInfo.link, "link"),
}
table.Append(out)
}
table.Append(out)
table.Render()

}
table.Render()
}

Binary file added skroutz-web-scraper-go
Binary file not shown.

0 comments on commit f155812

Please sign in to comment.