This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
43 lines (37 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
require('dotenv').config();
const { createTimeZone } = require('./dateTimes');
const fs = require('fs');
const { csvFilename, githubIdColumnNumber, timeZone, dateTimes } = require('./globals');
const { DateTime } = require('luxon');
const { Parser } = require('parse-csv');
const { fetchUserDataAndAddToOutput } = require('./starfish');
function parseCsvData() {
const parser = new Parser();
const zone = createTimeZone(timeZone);
const localStart = dateTimes[0].setZone(zone).toLocaleString(DateTime.DATETIME_FULL);
const localEnd = dateTimes[1].setZone(zone).toLocaleString(DateTime.DATETIME_FULL);
console.info(`Users that contributed between ${localStart} and ${localEnd}`);
const csvData = fs.readFileSync(csvFilename, { encoding: 'utf8' });
const datagrid = parser.parse(csvData).data;
return datagrid;
}
function runStarfish() {
const datagridOfPotentialContributorsInfo = parseCsvData();
const uniqueIds = new Set();
for (let rowNumber = 1; rowNumber < datagridOfPotentialContributorsInfo.length; rowNumber++) {
const currentRow = datagridOfPotentialContributorsInfo[rowNumber];
const currentId = currentRow[githubIdColumnNumber];
if (uniqueIds.has(currentId)) {
console.info(
`Ignoring Duplicate GitHub ID- you should probably erase one instance of this github id from your CSV: ${currentId}`
);
} else {
uniqueIds.add(currentId);
const delayToAvoidOverwhelmingMacNetworkStack = rowNumber * 10;
setTimeout(() => {
fetchUserDataAndAddToOutput(currentRow, dateTimes);
}, delayToAvoidOverwhelmingMacNetworkStack);
}
}
}
runStarfish();