Package: leetcode-export
LeetCode ExportPython script and Docker image to export your LeetCode submissions.📝 Table of ContentsDISCLAIMERAboutGetting startedScript argumentsSpecial mentionsLicense⚠️ DISCLAIMERThe 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 WEBSITEor you might receive ad DMCA Takedown
notice.Before using this script read theLeetCode Terms of Service.⚙️ AboutThis 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 further instructions read the
sectionDocker Image.🏁 Getting startedDownloadleetcode-exportTo useleetcode-exportdownload it from pypi.org, pull the docker image, or clone this repository.Download from pypi.orgRunpip install leetcode-exportto install leetcode-export, you might have to usepip3of your system. Then execute
run the scriptleetcode-export, optionally supply the script arguments. For more information read the
sectionscript arguments.Docker ImageDownload the docker image from DockerHub:dockerpullnevermendel/leetcode-exportDownload all your LeetCode submission in the current folder:dockerrun-it-v$(pwd):/usr/app/out--rmnevermendel/leetcode-exportClone the repositoryClone this repository:gitclonehttps://github.com/NeverMendel/leetcode-exportInstall all the needed dependencies:pipinstall-rrequirements.txtInstall leetcode-export in your system or just execute it:To install the script:pipinstall.To execute the script without installing it:python-mleetcode_export--foldersubmissionsLoginleetcode-exportrequires 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 browserOpen the browser's Dev ToolClick on the Network tabCopy 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:pythonleetcode-export--cookies{COOKIES}Using the interactive menu is preferred because it will avoid storing cookies in the command history.Script argumentsThe 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 exitProblem template argumentsProblem statement filename templateTo change the format of the problem statement filename provide a template as a string when executing the
script.pythonleetcode-export--problem-statement-filenamePROBLEM_STATEMENT_FILENAMEThe template can contain parameters that will later be replaced based on the LeetCode problem information. The available
parameters are the following:question_id:intdifficulty:strstats:strtitle:strtitle_slug:strDefault problem statement filename template:${question_id} - ${title_slug}.htmlProblem statement content templateTo change the format of the problem statement content provide a template as a string when executing the
script.pythonleetcode-export--problem-statement-contentPROBLEM_STATEMENT_CONTENTThe template can contain parameters that will later be replaced based on the LeetCode problem information. The available
parameters are the ones contained inproblem statement filename templateplus:content:strDefault 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 templateTo change the format of the submission filename, you can provide a template as a string when lunching the script.pythonleetcode-export--submission-filenameSUBMISSION_FILENAMEThe template can contain parameters that will later be replaced based on the submission information. The available
parameters are the following:id:intlang:strtime:strtimestamp:intstatus_display:strruntime:strurl:stris_pending:strtitle:strmemory:strcode:strcompare_result:strtitle_slug:strdate_formatted:strextension:strDefault submission filename
template:${date_formatted} - ${status_display} - runtime ${runtime} - memory ${memory}.${extension}Special mentionsThanks toskygragonfor
developingleetcode-cli, which I used as documentation for LeetCode APIs.
The license of leetcode-cli is availablehere.LicenseMIT License