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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const request = require("request-promise");
const filename = "sponsors.json";
const absoluteFilename = path.resolve(__dirname, filename);
const graphqlEndpoint = "https://api.opencollective.com/graphql/v2";
function createGraphqlQuery(page, pageSize) {
const offset = (page - 1) * pageSize;
return `query account {
account(slug: "socketio") {
members(role: BACKER, offset: ${offset}, limit: ${pageSize}) {
nodes {
tier {
name
}
account {
id
name
slug
website
socialLinks {
type
url
}
imageUrl(format: jpg)
}
totalDonations {
value
}
since
isActive
}
}
}
}`;
}
const customImages = new Map([
[
"skweezer-net",
{
url: "https://skweezer.net/buy-instagram-followers",
img: "/images/sponsors/skweezer-net.png",
alt: "visit skweezer to buy instagram followers today",
},
],
[
"route4me",
{
url: "https://route4me.com",
img: "/images/sponsors/route4me.png",
alt: "Route Planner and Route Optimizer",
},
],
[
"user-62981c05",
{
url: "https://superviral.io/",
img: "/images/sponsors/superviral.jpg",
alt: "Superviral",
},
],
[
"gem-m",
{
url: "https://www.noneedtostudy.com/take-my-online-class/",
img: "/images/sponsors/noneedtostudy.png",
alt: "Pay someone to take my online class - NoNeedToStudy.com",
},
],
[
"softorbits",
{
url: "https://www.softorbits.net/ai-undresser/",
img: "/images/sponsors/softorbits.png",
alt: "Undress AI by SoftOrbits",
}
]
]);
const customLinks = {
"casinotest-ltd": {
url: "https://www.casinotest.com/",
img: "https://images.opencollective.com/casinotest-ltd/7e3c899/logo.png",
alt: "CasinoTest Ltd.",
},
"veepn-vpn": {
url: "https://veepn.com/vpn-apps/download-vpn-for-pc/",
img: "https://images.opencollective.com/veepn-vpn/5e3715a/avatar.png",
alt: "VeePN VPN",
},
};
const nodeToSponsor = (node) =>
customLinks[node.account.slug] || {
url:
node.account.socialLinks.find((link) => link.type === "WEBSITE")?.url ||
node.account.website,
img: node.account.imageUrl,
alt: node.account.name,
};
function monthDiff(dateFrom, dateTo) {
return (
dateTo.getMonth() -
dateFrom.getMonth() +
12 * (dateTo.getFullYear() - dateFrom.getFullYear())
);
}
const NOW = new Date();
const AMOUNT_PER_MONTH = 100;
function sortByTotalDonationsOrStartDate(a, b) {
const sortByDonations = b.totalDonations.value - a.totalDonations.value;
const isSufficientDiff = Math.abs(sortByDonations) > AMOUNT_PER_MONTH;
if (isSufficientDiff) {
return sortByDonations;
}
return a.since.localeCompare(b.since);
}
const main = async () => {
console.log(`fetching sponsors from the graphql API`);
const validMembers = new Map();
for (let i = 1; i < 20; i++) {
const result = await request({
method: "POST",
uri: graphqlEndpoint,
body: { query: createGraphqlQuery(i, 500) },
json: true,
});
const sponsors = result.data.account.members.nodes;
console.log(`fetched ${sponsors.length} sponsors (page #${i})`);
if (sponsors.length === 0) {
break;
}
sponsors
.map((node) => {
const customImage = customImages.get(node.account.slug);
if (customImage) {
if (customImage.img) {
node.account.imageUrl = customImage.img;
}
if (customImage.url) {
node.account.website = customImage.url;
}
if (customImage.alt) {
node.account.name = customImage.alt;
}
}
return node;
})
.filter((node) => {
const isSubscriptionActive =
node.tier && node.tier.name === "Sponsors" && node.isActive;
const totalDonations = node.totalDonations.value;
const durationInMonths = monthDiff(new Date(node.since), NOW);
const hasSufficientOneTimeDonation =
totalDonations / durationInMonths >= AMOUNT_PER_MONTH;
const hasWebsite =
node.account.socialLinks.some((link) => link.type === "WEBSITE") ||
node.account.website; // website attribute is deprecated but still used in some cases
if (
(isSubscriptionActive || hasSufficientOneTimeDonation) &&
!hasWebsite
) {
console.log(
`${node.account.name} (https://opencollective.com/${node.account.slug}) has no website`,
);
}
return (
(isSubscriptionActive || hasSufficientOneTimeDonation) && hasWebsite
);
})
.forEach((node) => {
if (!validMembers.has(node.account.id)) {
// prevent duplicates, as some sponsors appear twice with { "tier": null } and { "tier": { "name": "Sponsors" }}
validMembers.set(node.account.id, node);
}
});
}
const activeSponsors = [...validMembers.values()]
.sort(sortByTotalDonationsOrStartDate)
.map(nodeToSponsor);
console.log(`found ${activeSponsors.length} active sponsors`);
fs.writeFileSync(absoluteFilename, JSON.stringify(activeSponsors, null, 2));
console.log(`content written to ${absoluteFilename}`);
};
main();