Skip to content

Commit 5807864

Browse files
committed
Add -remote option to forecast example
1 parent 8c519be commit 5807864

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

forecast/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ func main() {
4444
day := flag.Int("day", 0, "day (0-7)")
4545
scale := flag.Float64("scale", 1.5, "scale")
4646
padding := flag.Int("padding", 20, "padding")
47+
remote := flag.String("remote", "", "remote")
4748
out := flag.String("out", "", "out file")
4849
flag.Parse()
49-
if err := run(context.Background(), *verbose, *timeout, *query, *lang, *unit, *typ, *day, *scale, *padding, *out); err != nil {
50+
if err := run(context.Background(), *verbose, *timeout, *query, *lang, *unit, *typ, *day, *scale, *padding, *remote, *out); err != nil {
5051
fmt.Fprintf(os.Stderr, "error: %v\n", err)
5152
if strings.HasPrefix(err.Error(), "invalid lang ") {
5253
fmt.Fprint(os.Stderr, "\nvalid languages:\n")
@@ -58,7 +59,7 @@ func main() {
5859
}
5960
}
6061

61-
func run(ctx context.Context, verbose bool, timeout time.Duration, query, lang, unit, typ string, day int, scale float64, padding int, out string) error {
62+
func run(ctx context.Context, verbose bool, timeout time.Duration, query, lang, unit, typ string, day int, scale float64, padding int, remote, out string) error {
6263
// check
6364
lang = strings.ToLower(lang)
6465
if _, ok := langs[lang]; !ok && lang != "" {
@@ -84,7 +85,7 @@ func run(ctx context.Context, verbose bool, timeout time.Duration, query, lang,
8485
return fmt.Errorf("invalid padding %d", padding)
8586
}
8687

87-
query = "weather " + query
88+
query = "weather forecast " + query
8889

8990
// build search params
9091
v := make(url.Values)
@@ -93,6 +94,11 @@ func run(ctx context.Context, verbose bool, timeout time.Duration, query, lang,
9394
v.Set("hl", lang)
9495
}
9596

97+
// use remote allocator context if specified
98+
if remote != "" {
99+
ctx, _ = chromedp.NewRemoteAllocator(ctx, remote)
100+
}
101+
96102
// create chrome instance
97103
var opts []chromedp.ContextOption
98104
if verbose {

0 commit comments

Comments
 (0)