New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add omegup online judge #22
Changes from all commits
01c69a0
e63b6eb
dfcb7a6
6ba4fc1
3487c7b
035ab4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,8 @@ export default class Config { | |
debugCommand: "g++ -std=gnu++17 -DDEBUG -Wshadow -Wall", | ||
aliases: { | ||
codeforces: "54", | ||
atcoder: "4003" | ||
atcoder: "4003", | ||
omegaup: "cpp17-gcc" | ||
} | ||
}, | ||
py: { | ||
|
@@ -63,7 +64,8 @@ export default class Config { | |
debugCommand: "python3 -O", | ||
aliases: { | ||
codeforces: "31", | ||
atcoder: "4006" | ||
atcoder: "4006", | ||
omegaup: "py3" | ||
Comment on lines
+67
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default python aliases for each supported online judge in Config |
||
} | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export type LangAliases = { | ||
codeforces?: string; | ||
atcoder?: string; | ||
omegaup?: string; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
cpbooster "Competitive Programming Booster" | ||
Copyright (C) 2020 Sergio G. Sanchez V. | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { Page } from "playwright-chromium"; | ||
import OnlineJudge, { OnlineJudgeName } from "./OnlineJudge"; | ||
|
||
export default class Codeforces extends OnlineJudge { | ||
readonly onlineJudgeName = OnlineJudgeName.omegaup; | ||
readonly loginUrl = "https://omegaup.com/login/"; | ||
readonly blockedResourcesOnSubmit: Set<string> = new Set(["image", "font"]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sometimes we don't need to load "javascript" or "stylesheets" or images etc, by not loading them (blocking them) we can submit files faster. |
||
|
||
async isLoggedIn(page: Page): Promise<boolean> { | ||
const querySelector = "a[href*=logout]"; | ||
return (await page.$(querySelector)) !== null; | ||
} | ||
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usually this pattern works for most sites to detect if a user is logged in or not, so probably you would be just copying and pasting this. |
||
|
||
async uploadFile(filePath: string, page: Page, langAlias: string): Promise<boolean> { | ||
try { | ||
await page.click("a[href*=new-run]"); | ||
const inputFile = await page.$("input[type=file]"); | ||
if (inputFile) await inputFile.setInputFiles(filePath); | ||
await page.selectOption("select", { value: langAlias }); | ||
await page.click('button[type=submit][class="btn btn-primary"]'); | ||
return true; | ||
} catch (e) { | ||
console.log(e); | ||
return false; | ||
} | ||
} | ||
} | ||
Comment on lines
+32
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic to manipulate DOM/HTML elements in order to submit a source code file to the corresponding website |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ import open from "open"; | |
|
||
export enum OnlineJudgeName { | ||
codeforces = "codeforces", | ||
atcoder = "atcoder" | ||
atcoder = "atcoder", | ||
omegaup = "omegaup" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every online judge name should be declared in this enum, and use this one, instead of raw strings |
||
|
||
export default abstract class OnlineJudge { | ||
|
@@ -125,6 +126,8 @@ export default abstract class OnlineJudge { | |
return langAliases?.codeforces; | ||
case OnlineJudgeName.atcoder: | ||
return langAliases?.atcoder; | ||
case OnlineJudgeName.omegaup: | ||
return langAliases?.omegaup; | ||
Comment on lines
+129
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gets the language alias from the config depending on the OnlineJudge |
||
default: | ||
return undefined; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default cpp aliases for each supported online judge in Config