From 13a807854bf4d0258723ec3152b217ed4cf8e051 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 5 Feb 2018 23:48:16 +0100 Subject: Adds referential integrity. --- main.go | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'main.go') 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 } -- cgit v1.2.3