Skip to content

CLI Application for fetching leetcode problems locally using GraphQL API

License

Notifications You must be signed in to change notification settings

lmriccardo/leetcode-fetcher

Repository files navigation

LeetCode Problem Fetcher

A CLi Application for local fetching of leetcode problems

LeetCode Node.js TypeScript

NPM Package: https://www.npmjs.com/package/leetcode-fetcher-cli

Docker Repository: https://hub.docker.com/repository/docker/lmriccardo/leetcode-fetcher/general

Current Version: v0.0.4 (Development)

About ✨

When solving leetcode problems, I would have like to have a tool or a utility able to automatically provides me with a number of problems and, for each of them, creates a local instance with the problem description and the provided snippet of code. Thus avoiding every time to manually copy everything locally, resolve the imports and setup the tests.

The final result of this need is leetcode-fetcher, a simple cli applications that interacts with leetcode through the GraphQL endpoint, in order to fetch problems and user statistics.

Running the App 🚀

Cloning the repository and install locally

Up to now, to run the application you need first to clone the repository, install all the required node modules and then run.

git clone https://github.com/lmriccardo/leetcode-fetcher.git
npm install && npm run app

Please, make sure to have node.js and npm installed in your system.

Using Docker containers

Alternatively, it is possible to run the application using Docker.

docker run --rm -i -v ./:/leetcode lmriccardo/leetcode-fetcher:latest

Notice that, the bind mount -v ./:/leetcode is required to obtain the result on the host machine. When the application starts, the first command to execute must be

set FOLDER /leetcode

In order to set the correct output folder

From NPM Packages

The last way to run the cli application is to install it via npm

npm i leetcode-fetcher-cli

The command to run the application is just

lcfetcher

How the application works 💻

When first the application starts, the following line will appear:

>> (Type help for commands): 

If you type help the list with all possible commands will appear. That is, the application works giving specific commands and then pressing ENTER to execute it. Every time, either an error or the output pops out, you will always see the initial line and new commands can be given. Here is the list with all possible commands:

Name Syntax Description
Help help [cmd1 cmd2 ...] Shows the helper message for each given command. If no command is provided, consider all.
Set set [VAR value ...] Set the value of the specified variable. To inspect available variables use the show command.
Unset unset [VAR1 VAR2 ...] Unset variables bringing back to their default values.
Show show Shows values and informations about the application state and variables.
List list Locally fetches a number of problems from leetcode. The search is filtered using the variables set with set or unset
Detail detail <id/idx> [BYID|BYIDX] Print details about a specified problem. A problem is specified either by local indexing, or remote question IDs.
Fetch fetch <NAME|ID> <value> Fetch locally a single problem from remote. The problem is specified either using the title-slug or the remote ID.
Create create <idx> Create a problem instance in the provided target folder (which is a variable). The problem is specified only by the local index which means that must already exists locally.
Save save FILEPATH Saves the current state into a json file
Load load FILEPATH Loads the state from a json file
Clear clear Clears the screen content

In order to obtain more informations about the commands, run the help command.

An output example is already present in the ./examples/python/9-palindrome-number folder. It has been obtained running the following commands:

>> (Type help for commands): fetch ID 9
Total Problems: 3028
Fetched Problems: 1
[0] <ID=9> (Easy) PALINDROME NUMBER [Math]

>> (Type help for commands): set FOLDER ./examples/python
>> (Type help for commands): create 0
Result written in folder: examples\python\9-palindrome-number

Current Limitations and futures 🚧

  • Up to now, the only possible target language to save the problem code snippet is Python3.
  • Source code formatting bug when the problem introduces structures or mulitple function definition (try a tree problem)
  • Planning to introduce user statistics and user authentication (if possible)
  • Planning to introduce watchers that sumbit the code automatically (if possible)

About

CLI Application for fetching leetcode problems locally using GraphQL API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages