Archived
1
0
Fork 0

Configure headless browser address

Add `browser_address` configuration setting to define where is the headless
browser instead of relying on the default value.

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-03-01 13:11:58 +01:00
parent 6f002f007d
commit 45025def65
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
5 changed files with 11 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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)
}

View file

@ -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{

View file

@ -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 {