From 5ed537a6e3f7f57bd4c97306b7b9995a677c8b7b Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 31 Aug 2013 23:39:29 -0700 Subject: Adding real videos --- devfiles/scripts/bootstrap-cassandra.sh | 2 +- devfiles/scripts/bootstrap-strings.sh | 19 ++++++++---- devfiles/scripts/videos-from-csv.py | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100755 devfiles/scripts/videos-from-csv.py (limited to 'devfiles/scripts') diff --git a/devfiles/scripts/bootstrap-cassandra.sh b/devfiles/scripts/bootstrap-cassandra.sh index 220bd03..e0813a0 100755 --- a/devfiles/scripts/bootstrap-cassandra.sh +++ b/devfiles/scripts/bootstrap-cassandra.sh @@ -6,7 +6,7 @@ ## export TOOLS=`awk -F= '/jesterpm\.buildtools\.root/ { print $2 }' $HOME/.jesterpm-build-tools.properties` -export DEVFILES=$(dirname $0) +export DEVFILES=$(dirname $0)/.. $TOOLS/scripts/setup-cassandra.sh diff --git a/devfiles/scripts/bootstrap-strings.sh b/devfiles/scripts/bootstrap-strings.sh index 9552dcb..4e5eaf9 100755 --- a/devfiles/scripts/bootstrap-strings.sh +++ b/devfiles/scripts/bootstrap-strings.sh @@ -2,12 +2,17 @@ ## ## This script clears the strings ColumnFamily and then rebuilds it. +## If given a file name, it will put the commands into the file and not run it. ## export TOOLS=`awk -F= '/jesterpm\.buildtools\.root/ { print $2 }' $HOME/.jesterpm-build-tools.properties` -export DEVFILES=$(dirname $0) +export DEVFILES=$(dirname $0)/.. -TEMPFILE=`mktemp` +SAVEFILE="$1" +TEMPFILE="$SAVEFILE" +if [ -z "$SAVEFILE" ]; then + TEMPFILE=`mktemp` +fi cat > $TEMPFILE << EOF use GROW; @@ -21,12 +26,14 @@ create column family strings EOF # Fill with questions -./compile-questions.sh >> $TEMPFILE +$DEVFILES/scripts/compile-questions.sh >> $TEMPFILE # Fill with videos -./compile-videos.sh >> $TEMPFILE +$DEVFILES/scripts/compile-videos.sh >> $TEMPFILE # GO! -cassandra-cli < $TEMPFILE -rm $TEMPFILE +if [ -z "$SAVEFILE" ]; then + cassandra-cli < $TEMPFILE + rm $TEMPFILE +fi diff --git a/devfiles/scripts/videos-from-csv.py b/devfiles/scripts/videos-from-csv.py new file mode 100755 index 0000000..6adc8d7 --- /dev/null +++ b/devfiles/scripts/videos-from-csv.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +import sys,os,errno +import csv +import string +from string import Template + +BASE_URL="http://foursquaregrow.s3-website-us-east-1.amazonaws.com/" + +def mkjson(chapter, number, title, length, videos): + vtemplate = Template("""{ + "id": "$id", + "number": "$number", + "title": "$title", + "length": $length, + "urls": [""") + + urltemplate = Template("""{"src":"$src", "type":"$type"},""") + + directory = string.lower("videos/" + chapter) + try: + os.makedirs(directory) + except OSError as exc: + if exc.errno == errno.EEXIST and os.path.isdir(directory): + pass + else: + raise + filename = string.lower(directory + "/" + chapter + "-" + number + ".json") + with open(filename, 'w') as outfile: + outfile.write(vtemplate.substitute(dict(id=string.lower(chapter+"-"+number), + chapter=chapter, number=number, title=title, length=length))) + + for type,src in videos.iteritems(): + outfile.write(urltemplate.substitute(dict(type=type, src=BASE_URL + src))) + + outfile.seek(-1, 2) + outfile.write("]\n}") + +# This script reads lines from the given csv file and creates json files for +# each video in the videos/ directory. + +filename = sys.argv[1]; +with open(filename, 'rb') as csvfile: + reader = csv.reader(csvfile) + for row in reader: + chapter = row[0] + number = row[1] + title = row[2] + length = row[3] + h264 = row[4] + + videos = { "video/mp4": h264 } + + mkjson(chapter, number, title, length, videos) + -- cgit v1.2.3