-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (87 loc) · 3.12 KB
/
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
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
const express = require("express");
const app = express();
const puppeteer = require('puppeteer');
var cors = require('cors');
app.use(cors({origin: "*"}));
const { LeetCode } = require("leetcode-query");
app.get('/check/:username', (req, res)=>{
const d = new Date();
let time1 = d.getTime();
const {username} = req.params
const leetcode = new LeetCode();
leetcode.user(username).then((user)=>{
if (user.recentSubmissionList == null){
const d1 = new Date();
let time2 = d1.getTime();
res.status(200).send({
username: username,
recents:"",
time: time2-time1
})
}
else {
/**
recents = Array.from(user.recentSubmissionList, el=>{
if (el.statusDisplay == "Accepted"){el.title.toLowerCase().replace(new RegExp(' ', 'g'),"-")}
})
*/
recents = []
for (i in user.recentSubmissionList){
el = user.recentSubmissionList[i]
if (el.statusDisplay == "Accepted"){
var k = el.title.toLowerCase().replace(new RegExp(' ', 'g'),"-")
recents.push(k)
}
}
const d1 = new Date();
let time2 = d1.getTime();
recents = Array.from(new Set(recents))
res.status(200).send({
username: username,
recents:recents.toString(),
time: time2-time1
})
}
})
})
const PORT = process.env.PORT || 8080;
const joptions = {
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
}
}
/**
app.get('/check/:username', (req, res)=>{
const {username} = req.params
const url2 = `https://leetcode.com/${username}/`;
(async function scrape() {
const d = new Date();
let time1 = d.getTime();
const browser = await puppeteer.launch({ headless: true,args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const page = await browser.newPage();
await page.setExtraHTTPHeaders(joptions.headers);
await page.goto(url2);
let recents = await page.evaluate(() => {
let prob = Array.from(document.body.querySelectorAll("a > div > .text-label-1"), el=> el.innerHTML.toLowerCase().replace(new RegExp(' ', 'g'),"-"));
return prob;
});
browser.close();
const d1 = new Date();
let time2 = d1.getTime();
res.status(200).send({
username: username,
recents:recents.toString(),
time: time2-time1
})
})().catch(function(err){
console.log(err);
});
})
*/
app.listen(
PORT,
()=> console.log(`its alive on http://localhost:${PORT}`)
)