Skip to content
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 leetCode parser #244

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ dist/

# NPM (Yarn is used)
.package-lock.json
.cph
KorigamiK marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/parsers/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { HrbustOnlineJudgeProblemParser } from './problem/HrbustOnlineJudgeProbl
import { HydroProblemParser } from './problem/HydroProblemParser';
import { JutgeProblemParser } from './problem/JutgeProblemParser';
import { KattisProblemParser } from './problem/KattisProblemParser';
import { LeetCodeProblemParser } from './problem/LeetCodeProblemParser';
import { LibraryCheckerProblemParser } from './problem/LibraryCheckerProblemParser';
import { LibreOJProblemParser } from './problem/LibreOJProblemParser';
import { LightOJProblemParser } from './problem/LightOJProblemParser';
Expand Down Expand Up @@ -262,4 +263,5 @@ export const parsers: Parser[] = [

new YukicoderProblemParser(),
new YukicoderContestParser(),
new LeetCodeProblemParser(),
];
20 changes: 20 additions & 0 deletions src/parsers/problem/LeetCodeProblemParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Sendable } from '../../models/Sendable';
import { TaskBuilder } from '../../models/TaskBuilder';
import { htmlToElement } from '../../utils/dom';
import { Parser } from '../Parser';

export class LeetCodeProblemParser extends Parser {
public getMatchPatterns(): string[] {
return ['https://leetcode.com/problems/*', 'https://leetcode.com/contests/*/problems/*'];
}

public async parse(url: string, html: string): Promise<Sendable> {
console.log('My script engaged!');
const elem = htmlToElement(html);
const task = new TaskBuilder('HackerEarth').setUrl(url);
const titleElement = elem.querySelector('[data-cy="question-title"]');
task.setName(titleElement ? titleElement.textContent.trim() : 'LeetCodeProblem');
task.setCategory(elem.querySelector('[diff]').textContent.trim());
return task.build();
}
}