Skip to content

Instantly share code, notes, and snippets.

@stepheweffie
Last active March 22, 2018 11:36
Show Gist options
  • Save stepheweffie/ea383c52072de1bbc56541977d79ed18 to your computer and use it in GitHub Desktop.
Save stepheweffie/ea383c52072de1bbc56541977d79ed18 to your computer and use it in GitHub Desktop.
Takes screenshots of a live drawing and saves the recording then moves the clips (shots) into a clips directory. Needs to maximize browser.
'''
Takes a screen shot of user completing a drawing in the browser at
http://mrdoob.com/projects/harmony/#shaded, searches for a Phash of screenshot as a repeat drawing.
'''
import subprocess
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
import shutil
import os.path
import os
# instantiate a drawing by opening Harmony in Chrome
source = r'path\to\project'
dest = r'path\to\recordings'
clips = r'path\to\clips'
files = os.listdir(source)
clip_dirs = os.listdir(clips)
list_recs = os.listdir(dest)
def screenshots():
# TODO maximize browser window
options = webdriver.ChromeOptions()
#options.add_argument('--start-maximized')
options.binary_location = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
driver = webdriver.Chrome(chrome_options=options)
#try:
# driver.set_window_size(1900, 700)
#except WebDriverException:
# pass
count = 0
count2 = 1
try:
driver.get('http://mrdoob.com/projects/harmony/#shaded')
os.chdir(dest)
os.mkdir(r'path\to\new\recording', 755)
for dir in list_recs:
if '-' in dir:
count2 += 1
os.rename('recordings', 'recordings-%s' % count2)
recording = r'path\to\recordings\recording-%s' % count2
while driver:
os.chdir(recording)
count += 1
driver.save_screenshot('screen-' + str(count) + '.png')
clip = 'screen-' + str(count) + '.png'
shutil.copy(clip, clips)
list_clips = os.listdir(clips)
clip_file = str(len(list_clips))
os.chdir(clips)
os.rename(clip, clip_file + '.png')
except KeyboardInterrupt:
driver = False
screenshots()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment