diff options
| author | Jesse Morgan <jesse@jesterpm.net> | 2013-08-31 23:39:29 -0700 | 
|---|---|---|
| committer | Jesse Morgan <jesse@jesterpm.net> | 2013-08-31 23:39:29 -0700 | 
| commit | 063dc2cfc4a4758f22b681a0ea4461aeb6456e14 (patch) | |
| tree | 08b9ca2e0e0a400364744410851dda3ecb77b69e /devfiles/scripts | |
| parent | 014baa6529975341a314ed7bcc21d1dd639daab5 (diff) | |
Adding real videos
Diffstat (limited to 'devfiles/scripts')
| -rwxr-xr-x | devfiles/scripts/bootstrap-cassandra.sh | 2 | ||||
| -rwxr-xr-x | devfiles/scripts/bootstrap-strings.sh | 19 | ||||
| -rwxr-xr-x | devfiles/scripts/videos-from-csv.py | 55 | 
3 files changed, 69 insertions, 7 deletions
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) +  | 
