@ifvictr/

Hack Club Challenge Email Harvester

Nodejs

No description

fork
loading
Files
  • index.js
  • emails.json
  • package-lock.json
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
const axios = require("axios");
const fs = require("fs");

const API_URL = "https://api.hackclub.com/v1";

const getChallenges = async () => (await axios.get(`${API_URL}/challenges`)).data;

const getChallengePosts = async id => (await axios.get(`${API_URL}/challenges/${id}/posts`)).data;

const getPostComments = async id => (await axios.get(`${API_URL}/posts/${id}/comments`)).data;

const emails = new Set();

(async () => {
    try {
        let start = Date.now();
        const challenges = await getChallenges();
        console.log(`Total challenges: ${challenges.length}`);
        const posts = await Promise.all(
            await challenges
                .map(async challenge => await getChallengePosts(challenge.id))
                .reduce(async (allPosts, newPosts) => [...await allPosts, ...await newPosts], Promise.resolve([]))
        );
        console.log(`Total posts: ${posts.length}`);
        const comments = await Promise.all(
            await posts
                .map(async post => await getPostComments(post.id))
                .reduce(async (allComments, newComments) => [...await allComments, ...await newComments], Promise.resolve([]))
        );
        console.log(`Total comments: ${comments.length}`);
        comments.forEach(comment => {
            emails.add(comment.user.email);
        });
        console.log(emails.size);
        fs.writeFile("./emails.json", JSON.stringify({ emails: [...emails.values()] }, null, 2), err => {
            console.log("Emails saved!");
        });
    }
    catch(e) {
        console.log(e);
    }
})();
node v10.16.0