Skip to content

Commit

Permalink
remove hacky upload from node part
Browse files Browse the repository at this point in the history
  • Loading branch information
lauren mccarthy committed Jan 27, 2014
1 parent 2a18639 commit 7862f67
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@ git clone git@github.com:lmccart/untitled.git
cd untitled
npm install

sudo pip install boto (aws)
sudo pip install -U socketIO-client
(https://pypi.python.org/pypi/socketIO-client)
sudo apt-get install python-pyaudio
Expand Down
15 changes: 10 additions & 5 deletions intel.js
Expand Up @@ -10,12 +10,13 @@ module.exports = function(params) {
var intel = {};
intel.mturk = null;
intel.checkInterval = null;
intel.bucket;

// attempt login from config file
fs.readFile('./data/config.json', 'utf8', function(err, data) {
if (data) data = JSON.parse(data);
if (data.accessKeyId && data.secretAccessKey) {
intel.login(data);
if (data.aws.accessKeyId && data.aws.secretAccessKey) {
intel.login(data.aws);
}
});

Expand All @@ -35,12 +36,16 @@ module.exports = function(params) {
fs.readFile('./data/config.json', 'utf8', function(err, data) {
if (data) data = JSON.parse(data);
else data = {};
data.accessKeyId = params.accessKeyId;
data.secretAccessKey = params.secretAccessKey;

if (!data.aws) data.aws = {}
data.aws.accessKeyId = params.accessKeyId;
data.aws.secretAccessKey = params.secretAccessKey;

fs.writeFile('./data/config.json', JSON.stringify(data), function (err) {
if (err) throw err;
});

intel.bucket = params.accessKeyId+'_noodle/';
});

console.log('logged in');
Expand Down Expand Up @@ -73,7 +78,7 @@ module.exports = function(params) {
if (task.query.input[0] == 'camera') {
if (task.query.input[1] == 'take a photo') {
console.log("adding photo");
result.QuestionForm.Overview[0].Binary[0].DataURL[0] = 'https://s3-us-west-2.amazonaws.com/mc-untitled/'+task.id+'.png';
result.QuestionForm.Overview[0].Binary[0].DataURL[0] = 'https://s3-us-west-2.amazonaws.com/'+intel.bucket+task.id+'.jpg';
}
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -19,7 +19,6 @@
"xml2js": "~0.4.1",
"underscore": "~1.5.2",
"socket.io": "~0.9.16",
"json2xml": "~0.1.1",
"aws-sdk": "~2.0.0-rc8"
"json2xml": "~0.1.1"
}
}
3 changes: 3 additions & 0 deletions public/javascripts/main.js
Expand Up @@ -221,6 +221,9 @@ function buildActions() {
createDrop($('#'+new_id+'_'), actions, null);
}
});

// pend
$('#submit').show();
}

function updateMC() {
Expand Down
2 changes: 1 addition & 1 deletion python/test.py
Expand Up @@ -91,7 +91,7 @@ def run(self):

path = os.path.abspath(os.path.join(os.pardir, 'uploads/test.wav'))
#modals['audio'].play(path)
modals['camera'].photo("hi")
#modals['camera'].photo("hi")

#path = os.path.abspath(os.path.join(os.pardir, 'uploads/test.wav'))
#os.open(path)
Expand Down
20 changes: 0 additions & 20 deletions scheduler.js
Expand Up @@ -6,10 +6,6 @@ module.exports = function(server) {
, parseString = require('xml2js').parseString
, _ = require('underscore')
, io = require('socket.io').listen(server)
, aws = require('aws-sdk');

aws.config.loadFromPath('./data/config.json');
var s3 = new aws.S3();

var scheduler = {};
scheduler.tasks = [];
Expand Down Expand Up @@ -48,19 +44,6 @@ module.exports = function(server) {
socket.emit('register', { modal: task.trigger[0], event: task.trigger.slice(1) });
};

scheduler.uploadFile = function(file) {
fs.readFile('./uploads/'+file, function(err, file_buffer){
var params = {Bucket: 'mc-untitled', Key: file, Body: file_buffer, ACL:'public-read'};

s3.putObject(params, function(err, data) {

if (err) console.log(err)
else console.log("Successfully uploaded data to mc-untitled/"+file);

});
});
};

scheduler.removeTask = function(id) {

// remove hits as necessary
Expand Down Expand Up @@ -129,9 +112,6 @@ module.exports = function(server) {
if (err) throw err;
});

// hack, schedule upload to give python time to do task
setTimeout(function(){ scheduler.uploadFile(task.id+'.png'); }, 2000);

});
});
};
Expand Down

0 comments on commit 7862f67

Please sign in to comment.