-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (40 loc) · 1.68 KB
/
index.js
File metadata and controls
47 lines (40 loc) · 1.68 KB
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
"use strict";
// Dependencies
const request = require("request-async")
const { JSDOM } = require("jsdom")
const express = require("express")
const _ = require("lodash")
// Variables
const web = express()
const port = process.env.PORT || 8080
// Main
web.get("/", async(req, res)=>{
const { country } = req.query
const response = await request(`https://committers.top/${country.toLowerCase()}`)
if(response.body.match("Page not found &")) return res.json({
status: "failed",
message: "Invalid or unsupported country."
})
const dom = new JSDOM(response.body)
const data = []
const ranks = dom.window.document.querySelectorAll("td:nth-child(1)")
const usernames = dom.window.document.querySelectorAll("td:nth-child(2)")
const contributions = dom.window.document.querySelectorAll("td:nth-child(3)")
const pfps = dom.window.document.querySelectorAll("td:nth-child(4) > img")
try{
for( const i in ranks ) if(ranks[i].textContent && !_.find(data, { rank: ranks[i].textContent.replace(".", "") })) data.push({
rank: +ranks[i].textContent.replace(".", ""),
name: usernames[i].textContent.split("(")[1].replace(")", ""),
username: usernames[i].textContent.split("(")[0],
contribution: +contributions[i].textContent,
pfp: pfps[i].getAttribute("data-src"),
github: `https://github.com/${usernames[i].textContent.split("(")[0]}`
})
}catch{}
res.json({
status: "success",
data: data
})
})
web.use("*", (req, res)=>res.redirect("https://cspi.network/")) // You can delete if you want. :D
web.listen(port, ()=>console.log(`Server is running. Port: ${port}`))