diff options
| -rw-r--r-- | crawler/config.go | 3 | ||||
| -rw-r--r-- | crawler/shops.go | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/crawler/config.go b/crawler/config.go index f74253e..27aaa45 100644 --- a/crawler/config.go +++ b/crawler/config.go @@ -20,6 +20,7 @@ type Config struct { Debug bool FixDatabase bool + ShopIDs []string } // Parses the configuration and sets the configuration struct. @@ -35,6 +36,7 @@ func (c *Config) parseConfig(configFile string) { viper.SetDefault("Debug", false) viper.SetDefault("FixDatabase", false) viper.SetDefault("DisableURLShorter", false) + viper.SetDefault("ShopIDs", []string{}) // Name of the configuration file viper.SetConfigName("config") @@ -77,6 +79,7 @@ func (c *Config) setsConfig() { c.Debug = viper.GetBool("Debug") c.FixDatabase = viper.GetBool("FixDatabase") c.DisableURLShorter = viper.GetBool("DisableURLShorter") + c.ShopIDs = viper.GetStringSlice("ShopIDs") c.Polr_URL = viper.GetString("Polr_URL") c.Polr_API_Key = viper.GetString("Polr_API_Key") } diff --git a/crawler/shops.go b/crawler/shops.go index 1babc9d..be9bd53 100644 --- a/crawler/shops.go +++ b/crawler/shops.go @@ -1,6 +1,8 @@ package main import ( + "strings" + log "github.com/Sirupsen/logrus" ) @@ -96,7 +98,15 @@ func (app *App) getShops() ([]Shop, error) { Shops := []Shop{} - query := `SELECT id,name,short_url,url,logo_url,shipping_costs,free_shipping FROM 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 + ")" + } + + } + 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 { |
