Utility for auto-generating screenshots for exercises
Switch branches/tags
Nothing to show
Latest commit 9de7628 Jul 30, 2015 @nsfmc nsfmc Add default .arcconfig/.arclint file
Summary: as per https://phabricator.khanacademy.org/D18088
and the existence of ka-clone, we now add .arclint/.arcconfig
files to all repos by default making linting opt-out.

this adds both files to this repo which makes it so that all
our non-forked repositories all have arclint setup.

if you feel that this is no longer necessary or if this repo's
linting needs have changed, please feel free to update the
arclint/arcconfig pair or remove them altogether.

Test Plan: tested on thumbnail-sketches repo

Auditors: csilvers, mroth




exercise-screens is a utility that renders PNG screenshots of every static and Perseus exercise on Khan Academy. It is a very simple script that fetches a list of exercises from /api/v1/exercises and runs webkit2png on each one. The resulting images are stored in an Amazon S3 bucket for use in various places on the site.

For historical reasons, exercise-screens generates two versions of each screenshot. The first is a "full-size" screenshot that can be any dimensions but contains the entire <div id="problemarea">. The second is a cropped square screenshot whose dimensions are guaranteed to be 256 by 256 pixels. However, this behavior is easily customizable if you'd like differently sized output.

The first version of exercise-screens used PhantomJS to capture screenshots, but now it uses spicyj's fork of webkit2png and therefore only runs on Mac OS X now. The only other prerequisite is ImageMagick; Homebrew users can get it by running the command brew install imagemagick.

Setting up exercise-screens

git clone https://github.com/Khan/exercise-screens.git
cd exercise-screens
git submodule update --init
[sudo] pip install -r requirements.txt

Then customize the S3 bucket name in exercise-screens.py and create a file named secrets.py containing your Amazon Web Services credentials. See secrets.py.example for an example of how your secrets.py should look.

Running exercise-screens

Once your S3 credentials and bucket name are configured, simply run ./exercise-screens.py. The script will tell you what it is currently processing and how many errors it encounters. An error is not the end of the world; there currently exist some small inconsistencies in the Khan Academy content entities that cause some exercises to have URLs that don't exist.

To run exercise-screens at regular intervals, you can set it up as a LaunchAgent, which is like a cron job on OS X steroids. After customizing the example plist, do the following:

cp org.khanacademy.exercise-screens.plist.example ~/Library/LaunchAgents/org.khanacademy.exercise-screens.plist
launchctl load ~/Library/LaunchAgents/org.khanacademy.exercise-screens.plist

and then exercise-screens will be executed periodically by the system.

You might also be interested in setting up a custom error document for your S3 bucket, which will let you serve a nice placeholder image instead of an ugly 404 in the event that someone tries to access a screenshot that doesn't exist.