summaryrefslogtreecommitdiff
path: root/devfiles/scripts
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-08-31 23:39:29 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-08-31 23:39:29 -0700
commit5ed537a6e3f7f57bd4c97306b7b9995a677c8b7b (patch)
tree1e4e490e96a2c79559807a4452890d3d0cb36543 /devfiles/scripts
parenta1dfbf19b5e88897b46f4095ff3ef730eba26ba6 (diff)
Adding real videos
Diffstat (limited to 'devfiles/scripts')
-rwxr-xr-xdevfiles/scripts/bootstrap-cassandra.sh2
-rwxr-xr-xdevfiles/scripts/bootstrap-strings.sh19
-rwxr-xr-xdevfiles/scripts/videos-from-csv.py55
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)
+