Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feature: add topic tags and company tags#10

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
codewithsathya merged 1 commit intomainfromfeature/add-topic-tags
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
{
"name": "@leetnotion/leetcode-api",
"version": "1.7.1",
"version": "1.8.0",
"description": "Get user profiles, submissions, and problems on LeetCode.",
"type": "module",
"types": "lib/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletionssrc/_tests/leetcode-advanced.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,12 @@ describe('LeetCode Advanced', { timeout: 60_000 * 60 }, () => {
expect(Object.keys(problemTypes).length).toBeGreaterThan(3000);
});

it('should be able to get topic tags', async () => {
const topicTags = await lc.topicTags();
expect(Object.keys(topicTags).length).toBeGreaterThan(3000);
expect(topicTags['1'].length).greaterThanOrEqual(2);
});

it('should be able to get leetcode problems', async () => {
let count = 0;
const problems = await lc.getLeetcodeProblems(500, (problems) => {
Expand Down
8 changes: 8 additions & 0 deletionssrc/graphql/minimal-company-tags.graphql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
query questionCompanyTags {
companyTags {
name
questions {
questionFrontendId
}
}
}
21 changes: 21 additions & 0 deletionssrc/graphql/topic-tags.graphql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
query problemsetQuestionList(
$categorySlug: String
$limit: Int
$skip: Int
$filters: QuestionListFilterInput
) {
problemsetQuestionList: questionList(
categorySlug: $categorySlug
limit: $limit
skip: $skip
filters: $filters
) {
total: totalNum
questions: data {
questionFrontendId
topicTags {
name
}
}
}
}
53 changes: 53 additions & 0 deletionssrc/leetcode-advanced.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,24 @@ import COLLECT_EASTER_EGG from './graphql/collect-easter-egg.graphql?raw';
import COMPANY_TAGS from './graphql/company-tags.graphql?raw';
import LEETCODE_PROBLEMS_QUERY from './graphql/custom-problem.graphql?raw';
import IS_EASTER_EGG_COLLECTED from './graphql/is-easter-egg-collected.graphql?raw';
import MINIMAL_COMPANY_TAGS from './graphql/minimal-company-tags.graphql?raw';
import NO_OF_QUESTIONS from './graphql/no-of-problems.graphql?raw';
import QUESTION_FRONTEND_IDS from './graphql/question-frontend-ids.graphql?raw';
import TOPIC_TAGS from './graphql/topic-tags.graphql?raw';
import { LeetCode } from './leetcode';
import {
AllCompanyTags,
CompanyTagDetail,
DetailedProblem,
EasterEggStatus,
LeetcodeProblem,
MinimalCompanyTagDetail,
ProblemFieldDetails,
QueryParams,
RecentSubmission,
Submission,
SubmissionDetail,
TopicTagDetails,
} from './leetcode-types';
import problemProperties from './problem-properties';
import { memoryStringToNumber, runtimeStringToNumber } from './utils';
Expand DownExpand Up@@ -71,6 +75,29 @@ export class LeetCodeAdvanced extends LeetCode {
return true;
}

/**
* Get all topic tags for each question with question frontend id as key
* @returns
*/
public async topicTags(): Promise<Record<string, string[]>> {
await this.initialized;
const { data } = await this.graphql({
query: TOPIC_TAGS,
variables: {
categorySlug: '',
filters: {},
skip: 0,
limit: 1000000,
},
});
const problems = data.problemsetQuestionList.questions as TopicTagDetails[];
const questionIdToTopicTags: Record<string, string[]> = {};
for (const problem of problems) {
questionIdToTopicTags[problem.questionFrontendId] = problem.topicTags.map(({ name }) => name);
}
return questionIdToTopicTags;
}

/**
* Get all company tags with their details.
* For company wise question details, need to be authenticated and should be premium user.
Expand All@@ -84,6 +111,32 @@ export class LeetCodeAdvanced extends LeetCode {
return (data as AllCompanyTags).companyTags;
}

/**
* Get question frontend id to company tags mapping.
* Need to be authenticated and should be premium user
* @returns
*/
public async getQuestionIdCompanyTagsMapping(): Promise<Record<string, string[]>> {
await this.initialized;
const { data } = await this.graphql({
query: MINIMAL_COMPANY_TAGS,
});
const companyTags = data.companyTags as MinimalCompanyTagDetail[];
if (companyTags === null) {
throw new Error(`You should have leetcode premium to access company tags information`);
}
const questionIdToCompanyTags: Record<string, string[]> = {};
for (const companyTag of companyTags) {
for (const { questionFrontendId: id } of companyTag.questions) {
if (!questionIdToCompanyTags[id]) {
questionIdToCompanyTags[id] = [];
}
questionIdToCompanyTags[id].push(companyTag.name);
}
}
return questionIdToCompanyTags;
}

/**
* Checkin to collect a coin
* Need to be authenticated
Expand Down
10 changes: 10 additions & 0 deletionssrc/leetcode-types.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,6 +179,16 @@ export interface AllCompanyTags {
companyTags: CompanyTagDetail[];
}

export interface MinimalCompanyTagDetail {
name: string;
questions: { questionFrontendId: string }[];
}

export interface TopicTagDetails {
questionFrontendId: string;
topicTags: { name: string }[];
}

export interface CompanyTagDetail {
id: string;
imgUrl: string;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp