forked from afliu22/Alzheimers-ML
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
60 lines (53 loc) · 1.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var AWS = require('aws-sdk')
var s3 = new AWS.S3();
var params = {
Bucket: 'princetonhackbob',
Key: 'AlexaTest3.json'
};
var fileLoaded = false;
var fileData = null;
exports.handler = (event, context, callback) => {
if(!fileLoaded){
s3.getObject(params, function (err, data) {
if (err) console.log(err, err.stack);
else {
fileLoaded = true;
fileData = data;
parseJSON(event, context, callback)
}
});
} else {
parseJSON(event, context, callback)
}
};
function parseJSON(event, context, callback){
//Do the actual work here
// console.log(fileData.Body.toString())
const spawnSync = require("child_process").spawnSync;
const pythonProcess = spawnSync('python',["./main.py", fileData.Body.toString()]);
var checkValue;
// pythonProcess.stdout.on('data', function(data) {
// // res.send(data.toString());
// console.log(data.toString())
// } )
// pythonProcess.stdout.on('data', (data) => {
// console.log("hrloooo")
// checkValue = data.toString();
// console.log(checkValue)
// callback(null, {
// 'statusCode': 200,
// 'headers': {'Content-Type': 'application/json'},
// // 'body': fileData.Body.toString()
// 'body': checkValue
// }) //Then end
// });
console.log(pythonProcess)
console.log(pythonProcess.stderr.toString())
console.log(pythonProcess.stdout.toString())
return callback(null, {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
// 'body': fileData.Body.toString()
'body': true
})
}