forked from socketio/socket.io-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-sponsors.js
executable file
·169 lines (154 loc) · 4.69 KB
/
update-sponsors.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
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
#!/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 membersUrl = 'https://opencollective.com/socketio/members/all.json';
const graphqlEndpoint = 'https://api.opencollective.com/graphql/v2';
const graphqlQuery = `query account {
account(slug: "socketio") {
members(role: BACKER, limit: 500) {
nodes {
tier {
name
}
account {
name
slug
website
imageUrl
}
totalDonations {
value
}
createdAt
}
}
}
}`;
const customLinks = {
airtract: {
url: "https://www.airtract.com",
img: "/images/sponsors/airtract.jpg",
alt: "AirTract"
},
truevendor: {
url: "https://www.ramotion.com/agency/ui-ux-design",
img: "https://images.opencollective.com/truevendor/ddf2f01/logo.png",
alt: "ui ux design agency"
},
pinkelephant: {
url: "https://akasse-fagforening.dk/",
img: "/images/sponsors/a-kasse.png",
alt: "a-kasse"
},
"veselin-lalev": {
url: "https://casinodaddy.com",
img: "/images/sponsors/casinodaddy.png",
alt: "Casino Daddy"
},
papersowl2: {
url: "https://papersowl.com/research-papers",
img: "https://images.opencollective.com/papersowl2/510de59/logo.png",
alt: "Papersowl"
},
"buy-fineproxy-org": {
url: "https://buy.fineproxy.org/eng/",
img: "/images/sponsors/fineproxy.png",
alt: "Buy.Fineproxy.Org"
},
"nettikasinot-suomalaisille": {
url: "https://www.nettikasinotsuomalaisille.com/nettikasinot-ilman-rekisteroitymista/",
img: "/images/sponsors/netti.png",
alt: "Nettikasinot Suomalaisille"
},
"neue-online-casinos1": {
url: "https://www.neueonline-casinos.com/",
img: "/images/sponsors/neue.png",
alt: "Neue Online Casinos"
},
"aandelen-kopen1": {
url: "https://www.aandelenkopen.com",
img: "/images/sponsors/aandelenkopen.png",
alt: "Aandelen Kopen"
},
vpsservercom: {
"url": "https://www.vpsserver.com",
"img": "https://images.opencollective.com/vpsservercom/logo.png",
"alt": "VPS Hosting"
},
topvpnservice: {
"url": "https://www.topvpnservice.com/",
"img": "/images/sponsors/topvpnservice.png",
"alt": "TopVPNService"
},
"followerspromotion-com": {
url: "https://followerspromotion.com/buy-instagram-likes/",
img: "/images/sponsors/followerspromotion.svg",
alt: "followers promotions"
},
"online-value-group1": {
url: "https://deutschercasinobonus.com/casino-ohne-deutsche-lizenz/",
img: "/images/sponsors/deutschercasinobonus.jpg",
alt: "Deutschercasinobonus.com"
},
"quickbooks-tool-hub": {
url: "https://quickbookstoolhub.com/",
img: "/images/sponsors/quickbookstoolhub.png",
alt: "Quickbooks Tool Hub"
},
"friendlylikes": {
url: "https://friendlylikes.com/buy-instagram-likes/",
img: "https://images.opencollective.com/friendlylikes/fdf1b44/avatar.png",
alt: "Friendlylikes"
}
}
const nodeToSponsor = node => (customLinks[node.account.slug] || {
url: node.account.website,
img: node.account.imageUrl,
alt: node.account.name
});
const main = async () => {
console.log(`fetching sponsors from the graphql API`);
const [ members, sponsors ] = await Promise.all([
request({
method: 'GET',
uri: membersUrl,
json: true
}),
request({
method: 'POST',
uri: graphqlEndpoint,
body: { query: graphqlQuery },
json: true
}).then(result => result.data.account.members.nodes)
]);
const activeMembers = new Set();
members.forEach(member => {
if (member.isActive && member.profile) {
const slug = member.profile.substring('https://opencollective.com/'.length);
activeMembers.add(slug);
}
});
console.log(`${activeMembers.size} active members out of ${members.length}`);
const unique = new Set(activeMembers);
const activeSponsors = sponsors
.filter(n => {
const isSponsor = (!n.tier || n.tier.name === 'sponsors') && n.totalDonations.value >= 100;
const isActive = activeMembers.has(n.account.slug);
const hasWebsite = n.account.website;
return isSponsor && isActive && hasWebsite && unique.delete(n.account.slug);
})
.sort((a, b) => {
const sortByDonation = b.totalDonations.value - a.totalDonations.value;
if (sortByDonation !== 0) {
return sortByDonation;
}
return a.createdAt.localeCompare(b.createdAt);
})
.map(nodeToSponsor);
fs.writeFileSync(absoluteFilename, JSON.stringify(activeSponsors, null, 2));
console.log(`content written to ${absoluteFilename}`);
}
main();