-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.js
45 lines (38 loc) · 1.39 KB
/
submit.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
const puppeteer = require("puppeteer");
const chalk = require("chalk");
const loginURL = "https://codeforces.com/enter";
const submitURL = "https://codeforces.com/problemset/submit";
module.exports = {
submit: async (pid, pathtofile) => {
try {
const browser = await puppeteer.launch();
// const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(loginURL);
await page.type("#handleOrEmail", "[email protected]");
await page.type("#password", "password");
await page.click(".submit");
await Promise.all([page.waitForNavigation(), page.click(".submit")]);
await page.goto(submitURL);
await page.waitFor("input[name=submittedProblemCode]");
await page.type("input[name=submittedProblemCode]", pid);
await page.waitForSelector("input[type=file]");
await page.waitFor(1000);
const inputUploadHandle = await page.$("input[type=file]");
inputUploadHandle.uploadFile(pathtofile);
try {
await page.click(".submit");
await Promise.all([page.waitForNavigation(), page.click(".submit")]);
} catch (error) {
console.log(
chalk.red(
"Same code already submitted, try submitting different code."
)
);
}
await browser.close();
} catch (e) {
throw Error(e);
}
},
};