-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
75 lines (68 loc) · 2.2 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
71
72
73
74
75
var fs = require('fs');
var Typeform = require('@typeform/api-client');
const credentials = require('./credentials.json');
var typeformAPI = Typeform.createClient({
token: credentials.key
});
let page = 1;
let totalPages = 21;
let forms = [];
// 15th Aug'18 until 31st Dec'18
let formsInRange = [];
let formIds = [];
function getAllForms(callback) {
if (page < totalPages) {
typeformAPI.forms.list({ page: page, pageSize: 100, search: '' }).then(function(response) {
console.log(page);
// console.log(response);
response.items.forEach(item => {
forms.push(item);
});
getAllForms(callback);
page++;
});
} else {
callback();
}
}
startDate = new Date('2018-08-15T08:00:00+00:00');
endDate = new Date('2018-12-31T23:00:00+00:00');
getAllForms(function() {
forms.forEach(form => {
let formDate = new Date(form.last_updated_at);
if (formDate > startDate && formDate < endDate) {
formsInRange.push(form.id);
}
});
let set = new Set(formsInRange);
let arrayFromSet = Array.from(set);
formIds = arrayFromSet;
writeScript();
});
function writeScript() {
var stream = fs.createWriteStream('iMacrosScript.txt');
stream.once('open', function(fd) {
let before = `
SET !ERRORIGNORE YES
VERSION BUILD=12.5.2018.1105\n `;
stream.write(before);
formIds.forEach(id => {
let code = `
URL GOTO = https://admin.typeform.com/form/${id}/results#responses
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=TXT:"Download all responses"
TAG POS=1 TYPE=DIV ATTR=CLASS:"RadioBox-sc-1dpnbb5-0 eLzjUp"
ONDOWNLOAD FOLDER=* FILE=* WAIT=YES
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=TXT:Download\n`;
// ONDOWNLOAD FOLDER=C:\\Users\\UT04\\Downloads\\responses FILE=* WAIT=YES
// URL GOTO = https://admin.typeform.com/form/${id}/results#responses
// TAG POS=7 TYPE=DIV ATTR=TXT:Download<SP>all<SP>responses
// TAG POS=1 TYPE=DIV ATTR=TXT:XLSX<SP>file
// TAG POS=3 TYPE=DIV ATTR=TXT:Download
// ONDOWNLOAD FOLDER = C:\\Users\\UT04\\Downloads\\responses FILE=* WAIT=YES\n`;
stream.write(code);
});
// let after = 'SET !ERRORIGNORE NO';
// stream.write(after);
stream.end();
});
}