From d1ce36763bb1f5dc3d4f58b59a20cffc2b03a3a4 Mon Sep 17 00:00:00 2001 From: horus Date: Sun, 16 Sep 2018 17:17:04 +0200 Subject: Rename flags. Adds new flag to exclude shops. (crawler) --- crawler/init.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'crawler/init.go') diff --git a/crawler/init.go b/crawler/init.go index 668df2d..34e440e 100644 --- a/crawler/init.go +++ b/crawler/init.go @@ -17,15 +17,16 @@ func init() { // we need to parse the config because of log level setting configFile := flag.StringP("config", "c", "", "path to config file") - debug := flag.BoolP("debug", "d", false, "debug outputs") - verbose := flag.BoolP("verbose", "v", false, "same as --debug") - silent := flag.BoolP("silent", "s", false, "suppress outputs except warnings") - loglevel_f := flag.StringP("loglevel", "l", "Warn", `sets log level, can be "Warn", "Info" or "Debug"`) - flag.Bool("list-shops", false, `lists all crawlable shops`) - shopids_f := flag.StringP("restrict-shops", "r", "", `comma separated list of shop ids, crawls only these`) - user_agent_f := flag.StringP("user-agent", "u", "", "sets user agent") - delay_f := flag.Int("delay", 0, "toggles random delay between crawls") - ignore_robots_f := flag.Bool("ignore-robots-txt", true, "ignores robots.txt") + debug := flag.BoolP("debug", "d", false, "set log level to \"Debug\"") + verbose := flag.BoolP("verbose", "v", false, "set log level to \"Debug\", same as --debug") + silent := flag.BoolP("silent", "s", false, "suppress output except warnings") + loglevel_f := flag.String("loglevel", "Warn", `set log level, can be "Warn", "Info" or "Debug"`) + flag.BoolP("list-shops", "l", false, `list all crawlable shops`) + shopids_f := flag.StringP("only-shop", "o", "", `comma separated list of shop ids, crawl only these`) + not_shopids_f := flag.StringP("exclude-shop", "x", "", `comma separated list of shop ids, DO NOT crawl these`) + user_agent_f := flag.StringP("user-agent", "u", "", "set user agent") + delay_f := flag.Int("delay", 0, "enable and set delay in seconds between crawls (default 0)") + ignore_robots_f := flag.Bool("ignore-robots-txt", true, "ignore robots.txt") flag.Parse() loglevel := strings.ToLower(*loglevel_f) @@ -61,4 +62,11 @@ func init() { if "" != *shopids_f { _conf.ShopIDs = strings.Split(*shopids_f, ",") } + if "" != *not_shopids_f { + _conf.ExcludeShopIDs = strings.Split(*not_shopids_f, ",") + } + + if "" != *shopids_f && "" != *not_shopids_f { + log.Fatal("init.go: Config error: Cannot use both flags --exclude-shop and --only-shop at the same time.") + } } -- cgit v1.2.3