GithubHelp home page GithubHelp logo

chanbzz / leetcode-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from realvect0r/leetcode-api

0.0 0.0 0.0 284 KB

Leetcode API written with TypeScript, fully support async.

TypeScript 99.59% Shell 0.41%

leetcode-api's Introduction

Leetcode API

Leetcode API written with TypeScript, fully support async.

Thanks for the excellent work for leetcode-cli project! ❤️

GitHub package.json dynamic GitHub package.json version Build Status

Install

  • npm: npm i leetcode-api-ts
  • yarn: yarn add leetcode-api-ts

Usage

(async (): Promise<void> => {

    // Login 
    const leetcode: Leetcode = await Leetcode.build(
        "your username",
        "yout password",
        EndPoint.US     // or EndPoint.CN
    );

    // Get a special problem
    const problem: Problem = new Problem("two-sum");

    // Fetch more properties of this problem
    await problem.detail();

    // Show problem content, test case, code snippet etc
    const content: string = problem.content;
    const testcase: string = problem.simpleTestCase;
    const codeSnippets: Array<any> = problem.codeSnippets;

    // submit your answer
    problem.submit("your code language", "your code here");

    // Get All problems' base infomation
    const problems: Array<Problem> = await leetcode.getAllProblems();

    // Filter problems by status, difficulty, etc
    const acceptedProblems: Array<Problem> = problems.filter((p: Problem) => {
        return p.status === ProblemStatus.Accept;
    });

    acceptedProblems.forEach(async (problem: Problem) => {

        // Get all submissions
        const submissions: Array<Submission> = await problem.getSubmissions();

        // Filter submission which lang = cpp
        const cppSubmissions: Array<Submission> = submissions.filter((s: Submission) => {
            return s.lang === "cpp";
        });

        submissions.forEach((submission: Submission) => {

            // Get submission's status
            const code: string = await submission.detail();

            // Then you can handle them casually
        });
    });
})();

Tips

I especially recommend you fetch base properties first because of the large number of problems. Then call Problem.detail() or Submission.detail() fetch all properties of them.

TODO

  • Support Leetcode CN. [2019-08-24]
  • Fetch more user profile.
  • Fully parse submission status type.
  • Support problems filter by categories.
  • Support problems filter by companies.

Test

  • mv .env.example .env
  • Update your leetcode account in .env
  • yarn test.

Contribute

  • start: yarn start
  • build: yarn build
  • lint: yarn lint

License

MIT.

leetcode-api's People

Contributors

dependabot[bot] avatar realvect0r avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.