# LeetCode Export
Python script and Docker image to export your LeetCode submissions.
If you find LeetCode Export helpful, please consider giving it a star ⭐️. Your support helps me gauge its usage and motivates further development.
## 📝 Table of Contents
- [DISCLAIMER](#DISCLAIMER)
- [About](#about)
- [Getting started](#getting-started)
- [Script arguments](#script-arguments)
- [Special mentions](#special-mentions)
- [License](#license)
## ⚠️ DISCLAIMER <a name="disclaimer"></a>
The problems hosted on leetcode.com are intellectual propriety of LeetCode LLC unless specified otherwise. **DO NOT
UPLOAD THE DESCRIPTION OF LEETCODE PROBLEMS ON GITHUB OR ON ANY OTHER WEBSITE** or you might receive ad DMCA Takedown
notice.
Before using this script read the [LeetCode Terms of Service](https://leetcode.com/terms/).
## ⚙️ About <a name="about"></a>
This script uses LeetCode REST and GraphQL APIs to download all your LeetCode submitted solutions.
Before running the script, make sure that python3 is installed in your system.
If you prefer, you can use the Docker image to download LeetCode submissions. For more information read the
section [Docker Image](#docker-image).
## 🏁 Getting started <a name="getting-started"></a>
### Download `leetcode-export`
To use `leetcode-export` download it from pypi.org, pull the docker image, or clone this repository.
#### Download from pypi.org
Run `pip install leetcode-export` to install leetcode-export, you might have to use `pip3` of your system. Then execute
run the script `leetcode-export`, optionally supply the script arguments. For more information read the
section [script arguments](#script-arguments).
#### Docker Image
Download the docker image from DockerHub:
```bash
docker pull nevermendel/leetcode-export
```
Download all your LeetCode submission in the current folder:
```bash
docker run -it -v $(pwd):/usr/app/out --rm nevermendel/leetcode-export
```
#### Clone the repository
Clone this repository:
```bash
git clone https://github.com/NeverMendel/leetcode-export
```
Install all the needed dependencies:
```bash
pip install -r requirements.txt
```
Install leetcode-export in your system or just execute it:
- To install the script:
```bash
pip install .
```
- To execute the script without installing it:
```bash
python -m leetcode_export --folder submissions
```
### Login
`leetcode-export` requires a valid LeetCode account to download its submissions. Login to your LeetCode account by
providing the cookies. To log in using cookies, get them from an existing session.
**Steps required**:
- Login in to LeetCode in the web browser
- Open the browser's Dev Tool
- Click on the Network tab
- Copy the cookie header that can be found under Request Headers in any leetcode.com request.
You can insert the cookie string that you have just copied in the interactive menu (recommended) or you can pass it as a
program argument when lunching the script, like in the following example:
```bash
python leetcode-export --cookies {COOKIES}
```
Using the interactive menu is preferred because it will avoid storing cookies in the command history.
## Script arguments
The script accepts the following arguments:
```
usage: leetcode-export [-h] [--cookies COOKIES] [--folder FOLDER]
[--problem-folder-name PROBLEM_FOLDER_NAME]
[--no-problem-statement]
[--problem-statement-filename PROBLEM_STATEMENT_FILENAME]
[--problem-statement-content PROBLEM_STATEMENT_CONTENT]
[--submission-filename SUBMISSION_FILENAME]
[--only-accepted] [--only-last-submission]
[--language LANGUAGE_UNPROCESSED] [-v] [-vv] [-V]
Export LeetCode submissions
options:
-h, --help show this help message and exit
--cookies COOKIES set LeetCode cookies
--folder FOLDER set output folder
--problem-folder-name PROBLEM_FOLDER_NAME
problem folder name format
--no-problem-statement
do not save problem statement
--problem-statement-filename PROBLEM_STATEMENT_FILENAME
problem statement filename format
--problem-statement-content PROBLEM_STATEMENT_CONTENT
problem statement content format
--submission-filename SUBMISSION_FILENAME
submission filename format
--only-accepted save accepted submissions only
--only-last-submission
only save the last submission for each programming language
--language LANGUAGE_UNPROCESSED
save submissions for specified programming languages.
syntax: --language=<lang1>,<lang2>,...
languages: python, python3, c, cpp, csharp, java,
kotlin, mysql, mssql, oraclesql, javascript,
html, php, golang, scala, pythonml,
rust, ruby, bash, swift
example: --language=python,cpp,java
-v, --verbose enable verbose logging details
-vv, --extra-verbose enable more verbose logging details
-V, --version show program's version number and exit
```
### Problem template arguments
#### Problem statement filename template
To change the format of the problem statement filename provide a template as a string when executing the
script.
```bash
python leetcode-export --problem-statement-filename PROBLEM_STATEMENT_FILENAME
```
The template can contain parameters that will later be replaced based on the LeetCode problem information. The available
parameters are the following:
```python
question_id: int
difficulty: str
stats: str
title: str
title_slug: str
```
Default problem statement filename template: `${question_id} - ${title_slug}.html`
#### Problem statement content template
To change the format of the problem statement content provide a template as a string when executing the
script.
```bash
python leetcode-export --problem-statement-content PROBLEM_STATEMENT_CONTENT
```
The template can contain parameters that will later be replaced based on the LeetCode problem information. The available
parameters are the ones contained in [problem statement filename template](#problem-statement-filename-template) plus:
```python
content: str
```
Default problem statement content template:
`<h1>${question_id} - ${title}</h1><h2>Difficulty: ${difficulty} - <a href="https://leetcode.com/problems/${title_slug}/">${title_slug}</a></h2>${content}`
#### Submission filename template
To change the format of the submission filename, you can provide a template as a string when lunching the script.
```bash
python leetcode-export --submission-filename SUBMISSION_FILENAME
```
The template can contain parameters that will later be replaced based on the submission information. The available
parameters are the following:
```python
id: int
lang: str
time: str
timestamp: int
status_display: str
runtime: str
url: str
is_pending: str
title: str
memory: str
code: str
compare_result: str
title_slug: str
date_formatted: str
extension: str
```
Default submission filename
template: `${date_formatted} - ${status_display} - runtime ${runtime} - memory ${memory}.${extension}`
## Special mentions
Thanks to [skygragon](https://github.com/skygragon) for
developing [leetcode-cli](https://github.com/skygragon/leetcode-cli), which I used as documentation for LeetCode APIs.
The license of leetcode-cli is available [here](https://github.com/skygragon/leetcode-cli/blob/master/LICENSE).
## License
[MIT License](LICENSE)
Raw data
{
"_id": null,
"home_page": "https://github.com/NeverMendel/leetcode-export",
"name": "leetcode-export",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "leetcode,leetcode-solutions,leetcode-export",
"author": "Davide Cazzin",
"author_email": "28535750+NeverMendel@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/4a/84/5a9e1fff932bd89c8ed1dd47061f9b89e7eaca6ea39df5867ef5252f19c1/leetcode-export-2.4.0.tar.gz",
"platform": null,
"description": "# LeetCode Export\n\nPython script and Docker image to export your LeetCode submissions.\n\nIf you find LeetCode Export helpful, please consider giving it a star \u2b50\ufe0f. Your support helps me gauge its usage and motivates further development.\n\n## \ud83d\udcdd Table of Contents\n\n- [DISCLAIMER](#DISCLAIMER)\n- [About](#about)\n- [Getting started](#getting-started)\n- [Script arguments](#script-arguments)\n- [Special mentions](#special-mentions)\n- [License](#license)\n\n## \u26a0\ufe0f DISCLAIMER <a name=\"disclaimer\"></a>\n\nThe problems hosted on leetcode.com are intellectual propriety of LeetCode LLC unless specified otherwise. **DO NOT\nUPLOAD THE DESCRIPTION OF LEETCODE PROBLEMS ON GITHUB OR ON ANY OTHER WEBSITE** or you might receive ad DMCA Takedown\nnotice.\n\nBefore using this script read the [LeetCode Terms of Service](https://leetcode.com/terms/).\n\n## \u2699\ufe0f About <a name=\"about\"></a>\n\nThis script uses LeetCode REST and GraphQL APIs to download all your LeetCode submitted solutions.\n\nBefore running the script, make sure that python3 is installed in your system.\n\nIf you prefer, you can use the Docker image to download LeetCode submissions. For more information read the\nsection [Docker Image](#docker-image).\n\n## \ud83c\udfc1 Getting started <a name=\"getting-started\"></a>\n\n### Download `leetcode-export`\n\nTo use `leetcode-export` download it from pypi.org, pull the docker image, or clone this repository.\n\n#### Download from pypi.org\n\nRun `pip install leetcode-export` to install leetcode-export, you might have to use `pip3` of your system. Then execute\nrun the script `leetcode-export`, optionally supply the script arguments. For more information read the\nsection [script arguments](#script-arguments).\n\n#### Docker Image\n\nDownload the docker image from DockerHub:\n\n```bash\ndocker pull nevermendel/leetcode-export\n```\n\nDownload all your LeetCode submission in the current folder:\n\n```bash\ndocker run -it -v $(pwd):/usr/app/out --rm nevermendel/leetcode-export\n```\n\n#### Clone the repository\n\nClone this repository:\n\n```bash\ngit clone https://github.com/NeverMendel/leetcode-export\n```\n\nInstall all the needed dependencies:\n\n```bash\npip install -r requirements.txt\n```\n\nInstall leetcode-export in your system or just execute it:\n\n- To install the script:\n ```bash\n pip install .\n ```\n\n- To execute the script without installing it:\n ```bash\n python -m leetcode_export --folder submissions\n ```\n\n### Login\n\n`leetcode-export` requires a valid LeetCode account to download its submissions. Login to your LeetCode account by\nproviding the cookies. To log in using cookies, get them from an existing session.\n\n**Steps required**:\n\n- Login in to LeetCode in the web browser\n- Open the browser's Dev Tool\n- Click on the Network tab\n- Copy the cookie header that can be found under Request Headers in any leetcode.com request.\n\nYou can insert the cookie string that you have just copied in the interactive menu (recommended) or you can pass it as a\nprogram argument when lunching the script, like in the following example:\n\n```bash\npython leetcode-export --cookies {COOKIES}\n```\n\nUsing the interactive menu is preferred because it will avoid storing cookies in the command history.\n\n## Script arguments\n\nThe script accepts the following arguments:\n\n```\nusage: leetcode-export [-h] [--cookies COOKIES] [--folder FOLDER]\n [--problem-folder-name PROBLEM_FOLDER_NAME]\n [--no-problem-statement]\n [--problem-statement-filename PROBLEM_STATEMENT_FILENAME]\n [--problem-statement-content PROBLEM_STATEMENT_CONTENT]\n [--submission-filename SUBMISSION_FILENAME]\n [--only-accepted] [--only-last-submission]\n [--language LANGUAGE_UNPROCESSED] [-v] [-vv] [-V]\n\nExport LeetCode submissions\n\noptions:\n -h, --help show this help message and exit\n --cookies COOKIES set LeetCode cookies\n --folder FOLDER set output folder\n --problem-folder-name PROBLEM_FOLDER_NAME\n problem folder name format\n --no-problem-statement\n do not save problem statement\n --problem-statement-filename PROBLEM_STATEMENT_FILENAME\n problem statement filename format\n --problem-statement-content PROBLEM_STATEMENT_CONTENT\n problem statement content format\n --submission-filename SUBMISSION_FILENAME\n submission filename format\n --only-accepted save accepted submissions only\n --only-last-submission\n only save the last submission for each programming language\n --language LANGUAGE_UNPROCESSED\n save submissions for specified programming languages.\n syntax: --language=<lang1>,<lang2>,...\n languages: python, python3, c, cpp, csharp, java,\n kotlin, mysql, mssql, oraclesql, javascript,\n html, php, golang, scala, pythonml,\n rust, ruby, bash, swift\n example: --language=python,cpp,java\n -v, --verbose enable verbose logging details\n -vv, --extra-verbose enable more verbose logging details\n -V, --version show program's version number and exit\n```\n\n### Problem template arguments\n\n#### Problem statement filename template\n\nTo change the format of the problem statement filename provide a template as a string when executing the\nscript.\n\n```bash\npython leetcode-export --problem-statement-filename PROBLEM_STATEMENT_FILENAME\n```\n\nThe template can contain parameters that will later be replaced based on the LeetCode problem information. The available\nparameters are the following:\n\n```python\nquestion_id: int\ndifficulty: str\nstats: str\ntitle: str\ntitle_slug: str\n```\n\nDefault problem statement filename template: `${question_id} - ${title_slug}.html`\n\n#### Problem statement content template\n\nTo change the format of the problem statement content provide a template as a string when executing the\nscript.\n\n```bash\npython leetcode-export --problem-statement-content PROBLEM_STATEMENT_CONTENT\n```\n\nThe template can contain parameters that will later be replaced based on the LeetCode problem information. The available\nparameters are the ones contained in [problem statement filename template](#problem-statement-filename-template) plus:\n\n```python\ncontent: str\n```\n\nDefault problem statement content template:\n`<h1>${question_id} - ${title}</h1><h2>Difficulty: ${difficulty} - <a href=\"https://leetcode.com/problems/${title_slug}/\">${title_slug}</a></h2>${content}`\n\n#### Submission filename template\n\nTo change the format of the submission filename, you can provide a template as a string when lunching the script.\n\n```bash\npython leetcode-export --submission-filename SUBMISSION_FILENAME\n```\n\nThe template can contain parameters that will later be replaced based on the submission information. The available\nparameters are the following:\n\n```python\nid: int\nlang: str\ntime: str\ntimestamp: int\nstatus_display: str\nruntime: str\nurl: str\nis_pending: str\ntitle: str\nmemory: str\ncode: str\ncompare_result: str\ntitle_slug: str\ndate_formatted: str\nextension: str\n```\n\nDefault submission filename\ntemplate: `${date_formatted} - ${status_display} - runtime ${runtime} - memory ${memory}.${extension}`\n\n## Special mentions\n\nThanks to [skygragon](https://github.com/skygragon) for\ndeveloping [leetcode-cli](https://github.com/skygragon/leetcode-cli), which I used as documentation for LeetCode APIs.\nThe license of leetcode-cli is available [here](https://github.com/skygragon/leetcode-cli/blob/master/LICENSE).\n\n## License\n\n[MIT License](LICENSE)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python script to export your LeetCode solutions",
"version": "2.4.0",
"project_urls": {
"Homepage": "https://github.com/NeverMendel/leetcode-export"
},
"split_keywords": [
"leetcode",
"leetcode-solutions",
"leetcode-export"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d528abb28bca5909779c56a8dc50e1908515c07f58341c26bc76b015058929c2",
"md5": "c3dc6c48997f2ad585f03da81c8950e4",
"sha256": "d6cb7364eaf08d3cde14e290e311f0d95a3d4971f5508a60a12018ce9f29b3b5"
},
"downloads": -1,
"filename": "leetcode_export-2.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c3dc6c48997f2ad585f03da81c8950e4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 12377,
"upload_time": "2024-03-12T21:08:19",
"upload_time_iso_8601": "2024-03-12T21:08:19.814836Z",
"url": "https://files.pythonhosted.org/packages/d5/28/abb28bca5909779c56a8dc50e1908515c07f58341c26bc76b015058929c2/leetcode_export-2.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4a845a9e1fff932bd89c8ed1dd47061f9b89e7eaca6ea39df5867ef5252f19c1",
"md5": "70369c31fe009ba1a94c4d4c77e43a99",
"sha256": "4facad7642ee4a64c12a8651e7538b8b242810491f115d823fbde26056b8d702"
},
"downloads": -1,
"filename": "leetcode-export-2.4.0.tar.gz",
"has_sig": false,
"md5_digest": "70369c31fe009ba1a94c4d4c77e43a99",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 12710,
"upload_time": "2024-03-12T21:08:20",
"upload_time_iso_8601": "2024-03-12T21:08:20.991459Z",
"url": "https://files.pythonhosted.org/packages/4a/84/5a9e1fff932bd89c8ed1dd47061f9b89e7eaca6ea39df5867ef5252f19c1/leetcode-export-2.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-12 21:08:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NeverMendel",
"github_project": "leetcode-export",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "dataclasses_json",
"specs": []
},
{
"name": "requests",
"specs": []
}
],
"lcname": "leetcode-export"
}