Skip to content

Instantly share code, notes, and snippets.

@soonhokong
Last active August 29, 2015 14:01
Show Gist options
  • Save soonhokong/77876ce9d2b3e0d0df5a to your computer and use it in GitHub Desktop.
Save soonhokong/77876ce9d2b3e0d0df5a to your computer and use it in GitHub Desktop.
How we take photos at GHC9232

takeshot.sh

We are using imagesnap program to take a photo from command-line. On OSX, you can install it via homebrew.

#!/usr/bin/env bash
IMAGESNAP=/usr/local/bin/imagesnap
DEVICE="HD Pro Webcam C920"
DATE=`date "+%Y%m%d"`
DATETIME=`date "+%Y%m%d_%H%M%S"`
MIN=`date "+%M"`
IMAGE_PATH=/Users/soonhok/Dropbox/Photos/GHC9232

if [[ -e ${IMAGE_PATH}/shot || -e ${IMAGE_PATH}/SHOT || `expr ${MIN} % 15` == 0 ]]
then
    mkdir ${IMAGE_PATH}/${DATE} 2> /dev/null
    ${IMAGESNAP} -d "${DEVICE}" ${IMAGE_PATH}/${DATE}/${DATETIME}.jpg -w 5.00 -q
    rm -rf ${IMAGE_PATH}/SHOT ${IMAGE_PATH}/shot > /dev/null
fi

This script takes a photo every 15 min from DEVICE and saves them at IMAGE_PATH. On my imac, I have an entry for crontab to automatically run the script regularly:

  1 0-59 * * * * /Users/soonhok/bin/takeshot.sh

move_photos.sh

Having too many photos on Dropbox is not a good idea. So we have another machine which backups the shared photos from Dropbox and removes them from Dropbox if they are older than 5 days. It uses the following move_photos.sh script:

#!/usr/bin/env bash
DROPBOX_PHOTO_DIR=/Users/soonhok/Dropbox/Photos/GHC9232
BACKUP_DIR=/Users/Shared/GHC9232_Backup
WEEK_AGO=`date -j -v-5d "+%Y%m%d"`

TOGO=${DROPBOX_PHOTO_DIR}/${WEEK_AGO}

if [ -d "$TOGO" ]
then
	mv ${DROPBOX_PHOTO_DIR}/${WEEK_AGO} ${BACKUP_DIR}/
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment