summaryrefslogtreecommitdiff
path: root/crawler/shops.go
blob: 224ae96839388dc076f84fc27303ae098757266f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main

import (
	"strings"

	log "github.com/Sirupsen/logrus"
)

func (app *App) insertShops() error {
	shops := getShopsFromStruct()

	query := `INSERT IGNORE INTO shop (name, url, short_url, logo_url, shipping_costs, free_shipping) VALUES(?, ?, ?, ?, ?, ?)`

	for _, v := range shops {

		_, err := app.DB.Exec(query, v.Name, v.Url, v.Short_url, v.Logo_url, v.Shipping_costs, v.Free_shipping)
		if err != nil {
			return err
		}
	}

	return nil

}

func getShopsFromStruct() []Shop {
	Shops := []Shop{}

	Shops = append(Shops, Shop{
		Name:           "Bottleworld",
		Url:            "https://www.bottleworld.de",
		Short_url:      "https://l.fuselkoenig.de/bottleworld",
		Logo_url:       "",
		Shipping_costs: 599,
		Free_shipping:  "130€",
	})
	Shops = append(Shops, Shop{
		Name:           "MC Whisky",
		Url:            "https://www.mcwhisky.com",
		Short_url:      "https://l.fuselkoenig.de/mcwhisky",
		Logo_url:       "",
		Shipping_costs: 590,
		Free_shipping:  "75€",
	})
	Shops = append(Shops, Shop{
		Name:           "Rum & Co",
		Url:            "https://www.rumundco.de",
		Short_url:      "https://l.fuselkoenig.de/rumundco",
		Logo_url:       "",
		Shipping_costs: 595,
		Free_shipping:  "100€",
	})
	Shops = append(Shops, Shop{
		Name:           "Whic",
		Url:            "https://whic.de",
		Short_url:      "https://l.fuselkoenig.de/whic",
		Logo_url:       "",
		Shipping_costs: 590,
		Free_shipping:  "79€",
	})
	Shops = append(Shops, Shop{
		Name:           "Whisky.de",
		Url:            "https://www.whisky.de",
		Short_url:      "https://l.fuselkoenig.de/whiskyde",
		Logo_url:       "",
		Shipping_costs: 395,
		Free_shipping:  "50€",
	})
	Shops = append(Shops, Shop{
		Name:           "Whiskysite",
		Url:            "https://www.whiskysite.nl",
		Short_url:      "https://l.fuselkoenig.de/whiskysite",
		Logo_url:       "",
		Shipping_costs: 795,
		Free_shipping:  "",
	})
	Shops = append(Shops, Shop{
		Name:           "Whisky World",
		Url:            "https://www.whiskyworld.de",
		Short_url:      "https://l.fuselkoenig.de/whiskyworld",
		Logo_url:       "",
		Shipping_costs: 460,
		Free_shipping:  "77€",
	})
	Shops = append(Shops, Shop{
		Name:           "Whiskyzone",
		Url:            "https://www.whiskyzone.de",
		Short_url:      "https://l.fuselkoenig.de/whiskyzone",
		Logo_url:       "",
		Shipping_costs: 495,
		Free_shipping:  "75€",
	})
	Shops = append(Shops, Shop{
		Name:           "Drankdozijn",
		Url:            "https://Drankdozijn.de",
		Short_url:      "https://l.fuselkoenig.de/drankdozijn",
		Logo_url:       "",
		Shipping_costs: 595,
		Free_shipping:  "250€",
	})

	return Shops
}

func (app *App) getShops() ([]Shop, error) {

	Shops := []Shop{}

	var shop_query string
	if len(app.Config.ShopIDs) > 0 {
		shopIDs := strings.Join(app.Config.ShopIDs, `, `)
		if shopIDs != "" {
			shop_query = " WHERE id IN (" + shopIDs + ")"
		}

	} else if len(app.Config.ExcludeShopIDs) > 0 {
		excludeShopIDs := strings.Join(app.Config.ExcludeShopIDs, `, `)
		if excludeShopIDs != "" {
			shop_query = " WHERE id NOT IN (" + excludeShopIDs + ")"
		}
	}
	query := `SELECT id,name,short_url,url,logo_url,shipping_costs,free_shipping FROM shop ` + shop_query

	rows, err := app.DB.Queryx(query)
	if err != nil {
		return []Shop{}, err
	}
	defer rows.Close()

	for rows.Next() {
		var shop Shop
		err = rows.StructScan(&shop)

		if err != nil {
			return []Shop{}, err
		}
		log.Debug("Crawling: " + shop.Name)

		Shops = append(Shops, shop)
	}

	return Shops, nil
}