Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shot-scraper multi shots.yml -o output.png to selectively run shots from a YAML file #94

Closed
simonw opened this issue Oct 14, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Oct 14, 2022

In adding new screenshots to this multi file: https://github.com/simonw/datasette-screenshots/blob/main/shots.yml

I found myself wanting a way to run just a subset of the shots defined in the file.

Here's a design for that:

shot-scraper multi shots.yml -o binary-data.png
Screenshot of 'table' on 'https://latest.datasette.io/fixtures/binary_data' written to 'binary-data.png'
@simonw simonw added the enhancement New feature or request label Oct 14, 2022
@simonw
Copy link
Owner Author

simonw commented Oct 14, 2022

Here's a prototype that works pretty well already:

diff --git a/shot_scraper/cli.py b/shot_scraper/cli.py
index fc69fe6..aded7ef 100644
--- a/shot_scraper/cli.py
+++ b/shot_scraper/cli.py
@@ -315,6 +315,13 @@ def _browser_context(
     is_flag=True,
     help="Skip images that already exist",
 )
+@click.option(
+    "outputs",
+    "-o",
+    "--output",
+    help="Just take shots matching this output file",
+    multiple=True,
+)
 @browser_option
 @user_agent_option
 @reduced_motion_option
@@ -325,6 +332,7 @@ def multi(
     timeout,
     fail_on_error,
     noclobber,
+    outputs,
     browser,
     user_agent,
     reduced_motion,
@@ -366,6 +374,8 @@ def multi(
                 and pathlib.Path(shot["output"]).exists()
             ):
                 continue
+            if outputs and shot.get("output") not in outputs:
+                continue
             try:
                 take_shot(context, shot)
             except TimeoutError as e:

New help output:

Options:
  -a, --auth FILENAME             Path to JSON authentication context file
  --retina                        Use device scale factor of 2
  --timeout INTEGER               Wait this many milliseconds before failing
  --fail-on-error                 Fail noisily on error
  -n, --no-clobber                Skip images that already exist
  -o, --output TEXT               Just take shots matching this output file

@simonw simonw closed this as completed in cc027c2 Oct 14, 2022
simonw added a commit that referenced this issue Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant