-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path532PatternGFG_LC.js
More file actions
97 lines (81 loc) · 2.94 KB
/
532PatternGFG_LC.js
File metadata and controls
97 lines (81 loc) · 2.94 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
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
const puppeteer = require('puppeteer');
let getQuestionsGFG = require("./getQuestionsFromGFG").getQues;
let getQuestionsLC = require("./getQuestionsFromLC").getQues;
let createPDF=require("./convertJSON2PDF")
let questions = {}
let mainPage;
let mainBrowser;
const readline = require("readline");
let rl = readline.createInterface(
process.stdin,
process.stdout
)
rl.question("Which DSA do you want to practice?\n", async function (topic) {
await pattern532GFG(topic);
await pattern532LC(topic);
rl.close();
})
async function pattern532GFG(dsaTopic) {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
args: ["--start-maximized"],
slowMo: 50
});
let allPages = await browser.pages();
const pageGFG = allPages[0];
pageGFG.setDefaultNavigationTimeout(60000);
mainBrowser=browser;
mainPage=pageGFG;
await pageGFG.goto('https://practice.geeksforgeeks.org/explore/?page=1');
await pageGFG.reload()
await pageGFG.waitForSelector("div[href='#collapse4'] h4");
await pageGFG.evaluate(function () {
document.querySelector("div[href='#collapse4'] h4").click();
document.querySelector("#moreCategories").click();
})
await pageGFG.waitForSelector("#searchCategories");
await pageGFG.type("#searchCategories", dsaTopic)
await pageGFG.$('[style="font-size: 12px; padding: 10px; display: block;"]')
.then(async function(topicAvailable)
{
if(topicAvailable!=null)
await pageGFG.click('[style="font-size: 12px; padding: 10px; display: block;"]', { delay: 2000 })
else
{
console.log(`${dsaTopic} questions are not availabe on GFG`);
await pattern532LC(dsaTopic);
process.exit(0);
}
})
await pageGFG.click("#selectCategoryModal", { delay: 500 })
await pageGFG.click("div[href='#collapse1'] h4", { delay: 2000 });
questions["Easy Questions: "] = await getQuestionsGFG(pageGFG, 5, 0, true);
questions["Medium Questions: "] = await getQuestionsGFG(pageGFG, 3, 1, true)
questions["Hard Questions: "] = await getQuestionsGFG(pageGFG, 2, 2, true)
createPDF(JSON.stringify(questions),dsaTopic,"GFG");
}
async function pattern532LC(dsaTopic) {
const pageLC = mainPage;
await pageLC.goto('https://leetcode.com/problemset/all/');
await pageLC.click("#headlessui-popover-button-17", { delay: 1000 })
await pageLC.click("[placeholder='Filter topics']", { delay: 1000 })
await pageLC.type("[placeholder='Filter topics']", dsaTopic)
await pageLC.$(".mt-4.text-red-s")
.then(async function(questionsAvailable)
{
if(questionsAvailable==null)
await pageLC.click(".flex.flex-wrap.py-4.-m-1 span")
else
{
console.log(`${dsaTopic} questions not available on LeetCode.`);
process.exit(0);
}
})
questions["Easy Questions: "] = await getQuestionsLC(pageLC, 0, 5);
questions["Medium Questions: "] = await getQuestionsLC(pageLC, 1, 3);
questions["Hard Questions: "] = await getQuestionsLC(pageLC, 2, 2);
createPDF(JSON.stringify(questions),dsaTopic,"LeetCode");
mainBrowser.close();
}
module.exports={ GFG : pattern532GFG, LC : pattern532LC}