Skip to content

support translatedContent test on leetcode-cn.com #98

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

Merged
merged 1 commit into from
May 23, 2018
Merged
Changes from all commits
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
7 changes: 6 additions & 1 deletion lib/plugins/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ plugin.getProblem = function(problem, cb) {
' sampleTestCase',
' enableRunCode',
' metaData',
' translatedContent',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @EINDEX!

I assume that this new field would work for both leetcode.com and leetcode-cn.com?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the problems doesn't have chinese in leetcode-cn.com like this sum-of-distances-in-tree. The tranlatedContent filed is null.

' discussCategoryId',
' }',
'}'
Expand All @@ -156,7 +157,11 @@ plugin.getProblem = function(problem, cb) {

problem.totalAC = JSON.parse(q.stats).totalAccepted;
problem.totalSubmit = JSON.parse(q.stats).totalSubmission;
problem.desc = he.decode(cheerio.load(q.content).root().text());
if (!q.translatedContent) {
problem.desc = he.decode(cheerio.load(q.content).root().text());
}else{
problem.desc = he.decode(cheerio.load(q.translatedContent).root().text());
Copy link
Owner

@skygragon skygragon May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could combine into single line like:

problem.desc = he.decode(cheerio.load(q.translatedContent || q.content).root().text());

Assume that q.translatedContent would be null if talking with leetcode.com.

}
problem.templates = JSON.parse(q.codeDefinition);
problem.testcase = q.sampleTestCase;
problem.testable = q.enableRunCode;
Expand Down