summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2018-02-14 22:52:22 +0100
committerhorus2018-02-14 22:52:22 +0100
commit6140c5b7234b97d4a7b4bb26c87d316b3734f777 (patch)
tree57e4a2f597e114816149184871517dd419065a83
parent2692360f15a79be87d656f94c997e2ab34221ced (diff)
downloadalkobote-6140c5b7234b97d4a7b4bb26c87d316b3734f777.tar.gz
Add shop short url. (crawler)
-rw-r--r--crawler/config.go10
-rw-r--r--crawler/database.go3
-rw-r--r--crawler/shops.go16
3 files changed, 19 insertions, 10 deletions
diff --git a/crawler/config.go b/crawler/config.go
index 552d57a..b0964f8 100644
--- a/crawler/config.go
+++ b/crawler/config.go
@@ -23,12 +23,12 @@ type Config struct {
// Parses the configuration and sets the configuration struct.
func (c *Config) parseConfig(configFile string) {
- viper.SetDefault("DBDriver", "mysql")
- viper.SetDefault("DBDBName", "alkobote")
- viper.SetDefault("DBHost", "localhost")
- viper.SetDefault("DBPort", "3306")
+ viper.SetDefault("DB_Driver", "mysql")
+ viper.SetDefault("DB_DBName", "alkobote")
+ viper.SetDefault("DB_Host", "localhost")
+ viper.SetDefault("DB_Port", "3306")
- viper.SetDefault("DBPath", "./alkobote.db")
+ viper.SetDefault("DB_Path", "./alkobote.db")
viper.SetDefault("Debug", false)
diff --git a/crawler/database.go b/crawler/database.go
index d0bd632..1f38ca1 100644
--- a/crawler/database.go
+++ b/crawler/database.go
@@ -11,6 +11,7 @@ func (app *App) createTables() error {
id INTEGER PRIMARY KEY AUTO_INCREMENT,
name varchar(255) UNIQUE,
url varchar(255) UNIQUE,
+ short_url TEXT,
logo_url text,
shipping_costs int,
free_shipping text
@@ -59,7 +60,7 @@ func (app *App) createTables() error {
view_query := `CREATE OR REPLACE VIEW ` + v + `_view AS
SELECT
angebot.id, angebot.name, angebot.abv, angebot.volume, angebot.url as long_url, angebot.short_url as url,original_price/100 as original_price, discounted_price/100 as discounted_price, angebot.base_price/100 as base_price, image_url,
- shop.name as shop, shop.url as shop_url, shop.shipping_costs/100 as shipping_costs, shop.free_shipping, ROUND(100-((discounted_price/original_price)*100)) AS procent, spirit_type, created_at
+ shop.name as shop, shop.short_url as shop_url, shop.shipping_costs/100 as shipping_costs, shop.free_shipping, ROUND(100-((discounted_price/original_price)*100)) AS procent, spirit_type, created_at
FROM angebot
JOIN shop ON angebot.shop = shop.id
WHERE
diff --git a/crawler/shops.go b/crawler/shops.go
index 06b2b60..63c98ba 100644
--- a/crawler/shops.go
+++ b/crawler/shops.go
@@ -7,11 +7,11 @@ import (
func (app *App) insertShops() error {
shops := getShopsFromStruct()
- query := `INSERT IGNORE INTO shop (name, url, logo_url, shipping_costs, free_shipping) VALUES(?, ?, ?, ?, ?)`
+ 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.Logo_url, v.Shipping_costs, v.Free_shipping)
+ _, 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
}
@@ -26,7 +26,8 @@ func getShopsFromStruct() []Shop {
Shops = append(Shops, Shop{
Name: "Bottleworld",
- Url: "https://www.bottleword.de",
+ Url: "https://www.bottleworld.de",
+ Short_url: "https://l.fuselkoenig.de/bottleworld",
Logo_url: "",
Shipping_costs: 599,
Free_shipping: "130€",
@@ -34,6 +35,7 @@ func getShopsFromStruct() []Shop {
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€",
@@ -41,6 +43,7 @@ func getShopsFromStruct() []Shop {
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€",
@@ -48,6 +51,7 @@ func getShopsFromStruct() []Shop {
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€",
@@ -55,6 +59,7 @@ func getShopsFromStruct() []Shop {
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€",
@@ -62,6 +67,7 @@ func getShopsFromStruct() []Shop {
Shops = append(Shops, Shop{
Name: "Whiskysite.nl",
Url: "https://www.whiskysite.nl",
+ Short_url: "https://l.fuselkoenig.de/whiskysite",
Logo_url: "",
Shipping_costs: 795,
Free_shipping: "",
@@ -69,6 +75,7 @@ func getShopsFromStruct() []Shop {
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€",
@@ -76,6 +83,7 @@ func getShopsFromStruct() []Shop {
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€",
@@ -88,7 +96,7 @@ func (app *App) getShops() ([]Shop, error) {
Shops := []Shop{}
- query := `SELECT id,name,url,logo_url,shipping_costs,free_shipping FROM shop`
+ query := `SELECT id,name,short_url,url,logo_url,shipping_costs,free_shipping FROM shop`
rows, err := app.DB.Queryx(query)
if err != nil {