Last active
October 30, 2015 14:12
-
-
Save attakei/31a97944093a8a899880 to your computer and use it in GitHub Desktop.
Capture HTML5 slides by Ghost.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ghost import Ghost | |
ghost = Ghost() | |
session = ghost.start() | |
session.set_viewport_size(1135, 740) | |
session.open('http://io-2012-slides.googlecode.com/git/template.html') | |
session.evaluate('for (var idx = slidedeck.curSlide_; idx > 0; idx--) { slidedeck.prevSlide();}') | |
session.sleep(1) | |
session.capture_to('slide_1.png') | |
session.evaluate('slidedeck.nextSlide();') | |
session.sleep(1) | |
session.capture_to('slide_2.png') | |
session.evaluate('slidedeck.nextSlide();') | |
session.sleep(1) | |
session.capture_to('slide_3.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ghost import Ghost | |
ghost = Ghost() | |
session = ghost.start() | |
session.set_viewport_size(1135, 740) | |
session.open('http://io-2012-slides.googlecode.com/git/template.html') | |
maxIdx = int(session.evaluate('slidedeck.slides.length')[0]) | |
print(session.evaluate('slidedeck.slides.length')) | |
print('Max {} slides'.format(maxIdx)) | |
session.evaluate('for (var idx = slidedeck.curSlide_; idx > 0; idx--) { slidedeck.prevSlide();}') | |
for idx in range(maxIdx): | |
print('target: {}/{}'.format(idx, maxIdx)) | |
if idx != (maxIdx - 1): | |
curSlide = int(session.evaluate('slidedeck.curSlide_')[0]) | |
while idx >= curSlide: | |
session.evaluate('slidedeck.nextSlide();') | |
curSlide = int(session.evaluate('slidedeck.curSlide_')[0]) | |
print(idx, curSlide) | |
session.evaluate('slidedeck.prevSlide();') | |
session.sleep(1.5) | |
session.capture_to('_slides/slide_{}.png'.format(idx)) | |
session.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment