summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMax2018-02-05 23:48:16 +0100
committerMax2018-02-05 23:48:16 +0100
commit13a807854bf4d0258723ec3152b217ed4cf8e051 (patch)
tree14d7269d22ecf2d55055359af78b480a715bf82a /main.go
parent7ca22dc3e6a5fb1815de2c42b868458e1efb9ef9 (diff)
downloadalkobote-13a807854bf4d0258723ec3152b217ed4cf8e051.tar.gz
Adds referential integrity.
Diffstat (limited to 'main.go')
-rw-r--r--main.go50
1 files changed, 39 insertions, 11 deletions
diff --git a/main.go b/main.go
index 3dc3fc0..5255e1c 100644
--- a/main.go
+++ b/main.go
@@ -25,7 +25,7 @@ type App struct {
type Angebot struct {
Id int
Name string
- Shop string
+ Shop int
Url string
Original_price int
Discounted_price int
@@ -35,6 +35,7 @@ type Angebot struct {
}
type Shop struct {
+ Id int
Name string
Url string
Logo_url string
@@ -72,7 +73,17 @@ func main() {
log.Fatal(err)
}
- W := ScrapeHTML()
+ err = app.insertShops()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ shops, err := app.getShops()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ W := ScrapeHTML(shops)
err = app.save_offer(W)
if err != nil {
@@ -98,15 +109,32 @@ func printName(W []Angebot, name string) {
fmt.Println(string(output))
}
-func ScrapeHTML() []Angebot {
- W := ScrapeBottleWord()
- W = append(W, ScrapeMCWhisky()...)
- W = append(W, ScrapeRumundCo()...)
- W = append(W, ScrapeWhic()...)
- W = append(W, ScrapeWhiskyde()...)
- W = append(W, ScrapeWhiskysitenl()...)
- W = append(W, ScrapeWhiskyworld()...)
- W = append(W, ScrapeWhiskyzone()...)
+func ScrapeHTML(shops []Shop) []Angebot {
+ var W []Angebot
+
+ for _, shop := range shops {
+
+ switch shop.Name {
+ case "Bottleworld":
+ W = append(W, ScrapeBottleWord(shop)...)
+ case "MC Whisky":
+ W = append(W, ScrapeMCWhisky(shop)...)
+ case "Rum & Co":
+ W = append(W, ScrapeRumundCo(shop)...)
+ case "Whic":
+ W = append(W, ScrapeWhic(shop)...)
+ case "Whisky.de":
+ W = append(W, ScrapeWhiskyde(shop)...)
+ case "Whiskysite.nl":
+ W = append(W, ScrapeWhiskysitenl(shop)...)
+ case "Whisky World":
+ W = append(W, ScrapeWhiskyworld(shop)...)
+ case "Whiskyzone":
+ W = append(W, ScrapeWhiskyzone(shop)...)
+ default:
+ log.Println(shop.Name + ": No Crawler")
+ }
+ }
return W
}