Skip to content

Instantly share code, notes, and snippets.

@dotcomboom
Last active October 17, 2022 01:16
Show Gist options
  • Save dotcomboom/8d2093f29775c9ea425ab9933ec03070 to your computer and use it in GitHub Desktop.
Save dotcomboom/8d2093f29775c9ea425ab9933ec03070 to your computer and use it in GitHub Desktop.
WordPress Theme Screenshoter; This script was written to take screenshots of 1500+ legacy WordPress themes using a WAMP local host and Selenium. Very hacky!
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import shutil
import time
import os
wp_home = 'http://127.0.0.1/wordpress/'
wp_themes_folder = 'C:\\wamp64\\www\\wordpress\\wp-content\\themes\\'
wp_active_theme = 'twentytwentytwo'
r = 'C:\\Users\\Eric\\Desktop\\Wordpress themes\\'
logs = r + 'logs\\'
doing = r + 'doing\\'
done = r + 'done\\'
screenshots = r + 'screenshots\\'
err_done = r + 'err_done\\'
err_screenshots = r + 'err_screenshots\\'
driver = webdriver.Chrome()
driver.set_window_size(800, 600)
for file_name in os.listdir(doing):
i = os.path.join(doing, file_name)
if os.path.isfile(i):
# # delete contents of wp_active_theme_folder
# print('Resetting active theme folder')
try:
shutil.rmtree(wp_themes_folder + wp_active_theme)
except FileNotFoundError:
pass
# # extract the zip into wp_active_theme_folder
print(file_name)
shutil.unpack_archive(doing + file_name, wp_themes_folder)
halt = False
try:
shutil.move(wp_themes_folder + file_name.replace('.zip', ''), wp_themes_folder + wp_active_theme)
except:
print('{0} was skipped, something went wrong with extraction'.format(file_name))
halt = True
pass
if not halt:
driver.get(wp_home)
driver.save_screenshot(screenshots + file_name.replace('.zip', '.png'))
shutil.move(doing + file_name, done + file_name)
if 'xdebug-error' in driver.page_source:
print(file_name + ' theme throws errors; noting this')
with open(logs + 'themes with errors.txt', 'a') as f:
f.write(file_name + '\r\n')
shutil.move(screenshots + file_name.replace('.zip', '.png'), err_screenshots + file_name.replace('.zip', '.png'))
shutil.move(done + file_name, err_done + file_name)
@dotcomboom
Copy link
Author

The resulting archive is here, by the way! https://mega.nz/folder/RPYTlCIL#lXphlKRT5lAq-cYbZwjqEQ

For context: All of these themes were recovered from an archive of WordPress' own theme gallery at http://web.archive.org/web/20070209220132/http://themes.wordpress.net/page/2. If memory serves, I used wayback-machine-downloader to download all of them from the subdomain. All said and done this amounts to 1502 themes done and with screenshots generated. 248 threw PHP errors on the index with the tested WordPress version, and were put in a separate folder.

You'd might like to read these posts from Cammy's old blog for a lil more information on these themes. His WordPress Theme Archive hadn't panned out at the time, because putting each page together with screenshots and metadata took really long, but I hope to bring that idea back in the future with a healthy dose of automation.. 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment