You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
6 years ago
|
#!/bin/env python3
|
||
|
# a tool for taking screenshots of pelican websites versioned through git
|
||
|
# (c) roel roscam abbing 2018
|
||
|
# gplv3
|
||
|
import os, time
|
||
|
|
||
|
git_repo = '/home/r/Current/federation/wttf' #set the path to your pelican repo
|
||
|
outputdir = '/tmp/screenshots_wttf/' #set your output dir for the repo
|
||
|
|
||
|
os.chdir(git_repo)
|
||
|
commit_history = os.popen('git log --pretty="%H,%ad"').read().split('\n') # return commit hash and date as touple
|
||
|
|
||
|
|
||
|
if not os.path.exists(outputdir):
|
||
|
os.mkdir(outputdir)
|
||
|
|
||
|
|
||
|
def clear_cache(driver, timeout=60):
|
||
|
"""Clear the cookies and cache for the ChromeDriver instance."""
|
||
|
# navigate to the settings page
|
||
|
driver.get('chrome://settings/clearBrowserData')
|
||
|
|
||
|
# wait for the button to appear
|
||
|
wait = WebDriverWait(driver, timeout)
|
||
|
wait.until(get_clear_browsing_button)
|
||
|
|
||
|
# click the button to clear the cache
|
||
|
get_clear_browsing_button(driver).click()
|
||
|
|
||
|
# wait for the button to be gone before returning
|
||
|
wait.until_not(get_clear_browsing_button)
|
||
|
|
||
|
|
||
|
from selenium import webdriver # you need to set up a driver
|
||
|
|
||
|
for commit in commit_history:
|
||
|
if commit:
|
||
|
try:
|
||
|
hashn, commit_date = commit.split(',')
|
||
|
checkout = 'git checkout '+hashn
|
||
|
print(checkout)
|
||
|
os.system(checkout)
|
||
|
os.system('./develop_server.sh start') # otherwise replace this with make devserver?
|
||
|
time.sleep(5)
|
||
|
browser = webdriver.Chrome()
|
||
|
browser.set_window_size(1024, 768) # set the window size that you need
|
||
|
clear_cache(browser)
|
||
|
time.sleep(10)
|
||
|
browser.get('http://localhost:8000/')
|
||
|
date = commit_date.split(' +')[0].replace(' ','_').replace(':','-')
|
||
|
fn = '{}index_{}.png'.format(outputdir,date)
|
||
|
print(date, fn)
|
||
|
browser.save_screenshot(fn)
|
||
|
browser.quit()
|
||
|
os.system('./develop_server.sh stop')
|
||
|
except Exception as e:
|
||
|
|
||
|
pass
|
||
|
|
||
|
|
||
|
os.chdir('/home/r/Current/')
|