-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
70 lines (64 loc) · 2.04 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
61
62
63
64
65
66
67
68
69
70
import 'dotenv/config';
import { createWriteStream, mkdirSync } from 'node:fs';
import { Logger } from './src/logger.js';
import { getSurveyDetails } from './src/get-survey-details.js';
import { getSurveyResponseSchema } from './src/get-survey-response-schema.js';
import { getSurveyResponses } from './src/get-survey-responses.js';
import { join } from 'node:path';
const surveyId = process.argv[2];
const output = new URL('./output', import.meta.url);
mkdirSync(output, { recursive: true });
const dir = output.pathname;
const logger = new Logger();
process.stdout.write('working...');
try {
const csvFilePath = join(dir, `${surveyId}.csv`);
const csvDestinationStream = createWriteStream(csvFilePath);
const csvPromise = getSurveyResponses(
process.env.QUALTRICS_API_TOKEN,
process.env.QUALTRICS_DATA_CENTER,
surveyId,
csvDestinationStream,
'csv',
logger
);
const jsonResponseFilePath = join(dir, `${surveyId}-responses.json`);
const jsonResponseDestinationStream = createWriteStream(jsonResponseFilePath);
const jsonResponsePromise = getSurveyResponses(
process.env.QUALTRICS_API_TOKEN,
process.env.QUALTRICS_DATA_CENTER,
surveyId,
jsonResponseDestinationStream,
'json',
logger,
);
const jsonDetailsFilePath = join(dir, `${surveyId}-survey.json`);
const jsonDetailsPromise = getSurveyDetails(
process.env.QUALTRICS_API_TOKEN,
process.env.QUALTRICS_DATA_CENTER,
surveyId,
jsonDetailsFilePath,
logger,
);
const jsonSchemaFilePath = join(dir, `${surveyId}-schema.json`);
const jsonSchemaPromise = getSurveyResponseSchema(
process.env.QUALTRICS_API_TOKEN,
process.env.QUALTRICS_DATA_CENTER,
surveyId,
jsonSchemaFilePath,
logger,
);
await Promise.all([
jsonResponsePromise,
jsonDetailsPromise,
jsonSchemaPromise,
csvPromise
]);
process.stdout.write("\n");
process.stdout.write("\ndone\n");
} catch (e) {
process.stderr.write("nope");
process.stdout.write("\n");
process.stderr.write(logger.getEvents().join("\n"));
console.log(e);
}