forked from 11ty/11ty-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-supporters.js
92 lines (86 loc) · 2.33 KB
/
node-supporters.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require('dotenv').config();
const fs = require("fs-extra");
const fetch = require("node-fetch");
// const query = `
// query eleventyMembers {
// collective(slug: "11ty") {
// members {
// nodes {
// account {
// id
// name
// twitterHandle
// githubHandle
// imageUrl
// memberOf {
// nodes {
// account {
// slug
// }
// totalDonations {
// value
// }
// }
// }
// ... on Individual {
// email
// }
// }
// }
// }
// }
// }
// `;
const query = `
query eleventyMembers {
collective(slug: "11ty") {
members {
nodes {
account {
name
twitterHandle
githubHandle
... on Individual {
email
}
}
}
}
}
}
`;
(async function() {
if(!process.env.OPENCOLLECT_API_KEY) {
console.log( "Missing OPENCOLLECT_API_KEY. Do you have a .env file?" );
} else {
let url = "https://api.opencollective.com/graphql/v2";
let opts = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": process.env.OPENCOLLECT_API_KEY
},
body: JSON.stringify({ query })
};
let result = await fetch(url, opts)
.then(res => res.json())
.catch(function(error) {
console.error( error );
});
let alreadySentFile = await fs.readFile("./node-supporters/invited.csv", "utf-8");
let alreadySentEmails = alreadySentFile.split("\n").map(entry => entry.trim());
let emailsOnly = new Set();
let members = result.data.collective.members.nodes;
for(let member of members) {
if(member.account.email && alreadySentEmails.indexOf(member.account.email) === -1) {
emailsOnly.add(member.account.email);
}
}
await fs.writeFile("./node-supporters/node-supporters.json", JSON.stringify(result, null, 2));
console.log( "Wrote node-supporters.json." );
let newEmails = Array.from(emailsOnly);
await fs.writeFile("./node-supporters/need-to-invite.csv", newEmails.join("\n"));
console.log( "Wrote need-to-invite.csv." );
console.log( `${newEmails.length} ${newEmails.length != 1 ? "entries" : "entry"}.` );
}
})();