-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_download.js
67 lines (58 loc) · 1.41 KB
/
_download.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
61
62
63
64
65
66
67
// node 7.x
// uses async/await - promises
var rp = require('request-promise');
var fs = require('fs-extra');
var path = require('path');
const download = async (config) => {
try{
config.options = {
uri: config.uri,
method: 'GET',
headers: {
'Ocp-Apim-Subscription-Key': config.LUIS_subscriptionKey
}
};
config.response = {
success: {},
error: {}
};
let responseCSV = await rp(config.options);
await fs.writeFile(config.outFile, responseCSV,"utf-8");
/*
return getApi(config)
.then(writeFile)
.then(response => {
console.log("download done");
return response;
});
*/
console.log("download done");
return;
} catch(err){
return err;
}
}
/*
const writeFile = async (config) => {
try {
config.response.success.writeFile = await fs.writeJson(config.outFile,{ "downloaded": new Date().toLocaleString(),"utterances": utterances}
config.response.success.getApi, 'utf-8');
return config;
}
catch (err) {
config.response.error.writeFile = err;
return config;
}
}
const getApi = async (config) => {
try {
config.response.success.getApi = await rp(config.options);
return config;
}
catch (err) {
config.response.error.getApi = err;
return config;
}
}
*/
module.exports = download;