This repository tries to automate the steps needed to integrate your leetcode answers with github.
This includes:
- Importing a question:
- generates the question file,
- generates the test file (python3 only),
- updates the README
- Submiting a question solution
- Importing the latest accepted solution for each question with a single command
To install the needed libraries, activate a virtual environment (recommended) and run:
$ pip install leet2git
To install from source, download this repository, navigate to the folder and run:
$ pip install -e .[dev]
Currently, it is necessary to log into leetcode on either chrome or firefox before running the commands.
$ leet2git --help
Usage: leet2git [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
-s, --source-repository TEXT The path to the folder where the code will be saved.
Overrides the default config
-l, --language TEXT The language to run the command.
Overrides the default config
--help Show this message and exit.
Commands:
delete Delete a question and its files
get Generates all the files for a question
import-all Get all solutions and generate their files
init Creates a new configuration file and can generate a git repository.
reset Reset the configuration file
run Run a question on Leetcode Servers
submit Submit a question to Leetcode
Navigate to the source repository and run:
$ leet2git init --help
Usage: leet2git init [OPTIONS]
Creates a new configuration file and can generate a git repository.
Options:
-s, --source-repository TEXT the path to the folder where the code will be saved
-l, --language TEXT the default language
-c, --create-repo generates a git repository
Running this command will open the configuration file in the default editor.
To download the latest accepted submission for each solved problem:
$ leet2git import-all
To generate the files of a given question:
$ leet2git get --help
Usage: leet2git get [OPTIONS] QUESTION_ID
Generates all the files for a question
Args: question_id (int): the question id
To run a question on leetcode servers:
$ leet2git run --help
Usage: leet2git submit [OPTIONS] QUESTION_ID
Run a question on Leetcode Servers
Args: question_id (int): the question id
To submit a question to leetcode:
$ leet2git submit --help
Usage: leet2git submit [OPTIONS] QUESTION_ID
Submit a question to Leetcode
Args: question_id (int): the question id
To remove a downloaded problem (delete files and remove from readme):
$ leet2git delete --help
Usage: leet2git delete [OPTIONS] QUESTION_ID
Delete a question and its files
Args: question_id (int): the question id
Warning: This will delete the current question database and cannot be undone. Navigate to the source repository and run:
$ leet2git reset --help
Usage: leet2git reset [OPTIONS]
Reset the configuration file
Options:
-s, --source-repository TEXT the path to the folder where the code will be saved
-l, --language TEXT the default language
--soft (default) / --hard A soft reset only erases the database.
A hard reset also erase the files.
Running this command will open the configuration file in the default editor.
Running either the init or the reset command will open the configuration file in the default editor. The file location will also be printed in the terminal, so you can edit in manually later.
{
"language": "python3",
"source_path": "path_to_repository",
"readme": {
"show_difficulty": true,
"show_category": true
},
"source_code": {
"add_description": true
},
"test_code": {
"generate_tests": true
}
}
The default language the Download/Submit the questions. Can be overriden when running a command with the -l option.
Available Options:
- "bash"
- "c"
- "cpp"
- "csharp"
- "golang"
- "java"
- "javascript"
- "kotlin"
- "mysql"
- "php"
- "python"
- "python3"
- "ruby"
- "rust"
- "scala"
- "swift"
The path to the code repository
- show_difficulty: If true, will generate an extra section on README with different tables for each difficulty.
- show_category: If true, will generate an extra section on README with different tables for each category.
- add_description: If True, will add the problem description as comments in the source file.
- generate_tests: If true, will try to generate local test files for the question. Currently only python3 is supported.
Language | Generate/Import Question | Generate Local Tests | Submit/Run Question | Auto Import/Include Libraries |
---|---|---|---|---|
bash | ✔️ | ❌ | ✔️ | ❌ |
c | ✔️ | ❌ | ✔️ | ❌ |
cpp | ✔️ | ❌ | ✔️ | ❌ |
csharp | ✔️ | ❌ | ✔️ | ❌ |
golang | ✔️ | ❌ | ✔️ | ❌ |
java | ✔️ | ❌ | ✔️ | ❌ |
javascript | ✔️ | ❌ | ✔️ | ❌ |
kotlin | ✔️ | ❌ | ✔️ | ❌ |
mysql | ✔️ | ❌ | ✔️ | ❌ |
php | ✔️ | ❌ | ✔️ | ❌ |
python | ✔️ | ❌ | ✔️ | ❌ |
python3 | ✔️ | ✔️ | ✔️ | 🔶 |
ruby | ✔️ | ❌ | ✔️ | ❌ |
rust | ✔️ | ❌ | ✔️ | ❌ |
scala | ✔️ | ❌ | ✔️ | ❌ |
swift | ✔️ | ❌ | ✔️ | ❌ |
✔️: Fully Supported 🔶: Partially Supported ❌: Not Supported
After stabilizing the code, I am planning to improve the language suport. Contributions are always welcomed ;)
Thanks goes to these wonderful people (emoji key):
Yuri Rocha 💻 |
sungho-joo 💻 🐛 |
This project follows the all-contributors specification. Contributions of any kind welcome!