Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

Commit

Permalink
add hide_selector and browser_width args
Browse files Browse the repository at this point in the history
  • Loading branch information
chadmoone committed Mar 1, 2016
1 parent 8082144 commit bc9d9f8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ storing the images locally](config_templates/local.yaml.template) or

Required. The URL of the page you are screenshotting.

- **selector** - String
- **target_selector** - String

Optional. Defaults to `body`. The selector of the element you wish
to screenshot.
Expand Down Expand Up @@ -142,6 +142,11 @@ storing the images locally](config_templates/local.yaml.template) or

Optional. Default: `60`. Seconds to wait between taking screenshots

- **hide_selector**

Optional. The CSS selector(s) of elements on the page which you wish to
hide before capturing the screnshot (works by setting `display: none;`).

- **override_css_file**

Optional. Path to a CSS file that overrides any existing styles on the
Expand All @@ -153,6 +158,11 @@ storing the images locally](config_templates/local.yaml.template) or
Optional. Default: `2`. Seconds to wait after the page is loaded, to
ensure that any JavaScript has finished running.

- **browser_width** - Number

Optional. Default: `1440`. The width of the browser window, can be used
to capture a particular step in a responsive layout.

- **wait_for_js_signal** - Boolean

Optional. Default: `false`. Instruct depict to wait for the target
Expand Down
11 changes: 8 additions & 3 deletions config_templates/targets.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ time_between_screenshots: 180
failure_timeout: 45

targets:
- url: http://www.washingtonpost.com/
- url: https://www.washingtonpost.com/
slug: washington-post
selector: '#content > .wp-row > .wp-column > .container'
target_selector: '#right-rail > .pb-container > .pb-f-page-post-most'
aws_subpath: screenshots/wp-hp
page_load_delay: 2
- url: https://news.ycombinator.com/
Expand All @@ -23,6 +23,11 @@ targets:
page_load_delay: 4
- url: http://www.drudgereport.com/
slug: drudge-report
selector: '#drudgeTopHeadlines'
target_selector: '#drudgeTopHeadlines'
aws_subpath: screenshots/dr-hp
page_load_delay: 2
- url: https://www.washingtonpost.com/
slug: mobile-post-no-headlines
target_selector: '#main-content .top-table'
hide_selector: '.headline'
browser_width: 375
12 changes: 7 additions & 5 deletions whippersnapper/screenshotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ def take_screenshots(self):
try:
self.depict(
current_target.url,
current_target.selector,
current_target.target_selector,
current_target.local_filepath,
# Depict's delay argument is defined in milliseconds
str(int(current_target.page_load_delay) * 1000)
str(int(current_target.page_load_delay) * 1000),
current_target.hide_selector,
str(current_target.browser_width)
)
targets.append(current_target)
except RuntimeError as e:
logging.error(e)
return targets

def depict(self, url, selector, destination, page_load_delay):
def depict(self, url, target_selector, destination, page_load_delay, hide_selector, browser_width):
"""
Runs the command-line utility `depict`.
"""
args = ['depict', url, destination, '-s', selector,
'--delay', page_load_delay]
args = ['depict', url, destination, '-s', target_selector,
'-d', page_load_delay, '-w', browser_width, '-H', hide_selector]

override_css_file = self.config.get('override_css_file')
if override_css_file:
Expand Down
6 changes: 4 additions & 2 deletions whippersnapper/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def check_config_options(self, target_config):
if not option in target_config:
raise RuntimeError('Missing required option %s' % option)

if not 'selector' in target_config:
target_config['selector'] = 'body'
if not 'target_selector' in target_config:
target_config['target_selector'] = 'body'


def combine_config_options(self, global_config, target_config):
Expand All @@ -35,6 +35,8 @@ def combine_config_options(self, global_config, target_config):
'override_css_file',
'wait_for_js_signal',
'failure_timeout',
'hide_selector',
'browser_width'
]

for option in options_whitelist:
Expand Down
2 changes: 2 additions & 0 deletions whippersnapper/whippersnapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def load_config(self, config_filepath):
'log_file': log_file,
'delete_local_images': False,
'time_between_screenshots': 60,
'hide_selector': ' ',
'override_css_file': None,
'page_load_delay': 2,
'browser_width': 1440,
'wait_for_js_signal': False,
'failure_timeout': 30,
}
Expand Down

0 comments on commit bc9d9f8

Please sign in to comment.