diff --git a/README.md b/README.md index d675b50..bb78fc1 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Options: * `hashtags`: list of key/value used to append hashtags to each tweet. Key is the pattern to match in the product name, value is the string to append to the tweet. For example, `{"twitter": {"hashtags": [{"rtx 3090": "#nvidia #rtx3090"}]}}` will detect `rtx 3090` to append `#nvidia #rtx3090` at the end of the tweet. * `include_regex` (optional): include products with a name matching this regexp * `exclude_regex` (optional): exclude products with a name matching this regexp +* `browser_address` (optional): set headless browser address (ex: `http://127.0.0.1:9222`) ## How to contribute diff --git a/config.go b/config.go index c19c223..9ac5505 100644 --- a/config.go +++ b/config.go @@ -8,10 +8,11 @@ import ( // Config to store JSON configuration type Config struct { - TwitterConfig `json:"twitter"` - URLs []string `json:"urls"` - IncludeRegex string `json:"include_regex"` - ExcludeRegex string `json:"exclude_regex"` + TwitterConfig `json:"twitter"` + URLs []string `json:"urls"` + IncludeRegex string `json:"include_regex"` + ExcludeRegex string `json:"exclude_regex"` + BrowserAddress string `json:"browser_address"` } // TwitterConfig to store Twitter API secrets diff --git a/main.go b/main.go index 24cdd42..31fa387 100644 --- a/main.go +++ b/main.go @@ -100,7 +100,7 @@ func main() { } // create parser - parser, err := NewParser(config.IncludeRegex, config.ExcludeRegex) + parser, err := NewParser(config.BrowserAddress, config.IncludeRegex, config.ExcludeRegex) if err != nil { log.Fatalf("could not create parser: %s", err) } diff --git a/parser.go b/parser.go index d042de9..443162c 100644 --- a/parser.go +++ b/parser.go @@ -22,7 +22,7 @@ type Parser struct { } // NewParser to create a new Parser instance -func NewParser(includeRegex string, excludeRegex string) (*Parser, error) { +func NewParser(browserAddress string, includeRegex string, excludeRegex string) (*Parser, error) { var err error var includeRegexCompiled, excludeRegexCompiled *regexp.Regexp @@ -44,7 +44,7 @@ func NewParser(includeRegex string, excludeRegex string) (*Parser, error) { log.Debugf("creating context with headless browser drivers") ctx := context.Background() - ctx = drivers.WithContext(ctx, cdp.NewDriver()) + ctx = drivers.WithContext(ctx, cdp.NewDriver(cdp.WithAddress(browserAddress))) ctx = drivers.WithContext(ctx, http.NewDriver(), drivers.AsDefault()) return &Parser{ diff --git a/parser_test.go b/parser_test.go index 6c9f83f..9070c6d 100644 --- a/parser_test.go +++ b/parser_test.go @@ -18,7 +18,7 @@ func TestFilterInclusive(t *testing.T) { for i, tc := range tests { t.Run(fmt.Sprintf("TestFilterInclusive#%d", i), func(t *testing.T) { - p, err := NewParser(tc.regex, "") + p, err := NewParser("", tc.regex, "") if err != nil { t.Errorf("failed to initialize parser: %s", err) } else { @@ -58,7 +58,7 @@ func TestFilterExclusive(t *testing.T) { for i, tc := range tests { t.Run(fmt.Sprintf("TestFilterExclusive#%d", i), func(t *testing.T) { - p, err := NewParser("", tc.regex) + p, err := NewParser("", "", tc.regex) if err != nil { t.Errorf("failed to initialize parser: %s", err) } else {