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.1.1 (Release), v0.1.2 (Development)
GitHub Pages Documentation is in construction 👷
Give a look to TODO.md for upcoming changes
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, user statistics, run tests remotely and submit a solution.
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.
Alternatively, it is possible to run the application using Docker.
docker run --rm -it -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
NOTE: Within Docker containers, user login with browser is not available. The only possible solution is to load a pre-saved JSON state with a logged in user.
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
When first the application starts, the following line will appear:
[Current DateTime] >> (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 [sensitive] |
Shows values and informations about the application state and variables. If sensitive is given then also user cookies are shown. |
List | list |
Locally fetches a number of problems from leetcode. The search is filtered using the variables set with set or unset |
Detail | detail idx |
Print details about a specified problem. A problem is specified either by local indexing, or remote question IDs. |
Fetch | fetch <title|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 |
Login | login [force] |
Open a browser to perform the login and starts a leetcode session. |
Inspect | inspect [username] |
Inspect a given user profile if it exists, or the current logged one |
Daily | daily [create] |
Fetch the current daily question and optionally create an instance |
Quit | quit |
Quit the application |
Watch | watch <question-idx|daily> |
Cache the given problem for future tests or submissions. An instance of the given problem is create if it does not exists. |
Test | test |
Test the cached problem with leetcode remotely (see watch ) |
Submit | submit |
Submit a solution of the cached problem in leetcode (see watch ) |
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:
[XXX] >> (Type help for commands): fetch id 9
Fetched Problems : 1
STATUS IDX ID DIFFICULTY TITLE TAGS
❌🙉💲 0 9 Easy Palindrome Number Math
[XXX] >> (Type help for commands): set FOLDER ./examples/python
[XXX] >> (Type help for commands): create 0
[INFO] Result written in folder: examples\python\9-palindrome-number
- Up to now, the only possible target language to save the problem code snippet is Python3.