Scrape LeetCode and automatically upload your solutions to GitHub.
Clone this repo:
git clone https://github.com/Ismail-Mahmoud/lcws.git
Go to the project directory:
cd lcws
[Optional] Create a virtual environment and activate it:
python3 -m venv venv
source venv/bin/activate
Install the package:
pip3 install .
Copy this file to a new file named config.toml
under the same directory. This new file will be the main config file containing LeetCode and GitHub configurations which will be used to access your LeetCode account and GitHub repo.
Under leetcode
section, set the following values:
base_url
: LeetCode base URL (set by default)login_page
: LeetCode login page (set by default)user
: Your LeetCode username or emailpassword
: Your LeetCode password
*Your LeetCode credentials is used by the web scraper to login to your account and fetch submissions
Under github
section, set the following values:
api_base_url
: GitHub API base URL (set by default)access_token
: Your GitHub access token*owner
: Your GitHub usernamerepo
: Name of the repo to which the solution will be uploadedbranch
: Name of the branch to which the solution will be uploadeddirectory
: Path of the directory to which the solution will be uploaded (for example,leetcode/solutions
)
*You can generate your access token here. Select only the target repo and under Repository permissions
, grant Read and write
access for Contents
.
Just run the following command:
lcws <URL>
where URL
is a valid URL of one of the following:
- LeetCode problem (
https://leetcode.com/problems/<problem-name>/
). In this case, the last accepted submission will be fetched. - LeetCode submission (
https://leetcode.com/problems/<problem-name>/submissions/<submission-id>/
).
For help, run:
lcws --help
-
Accept submission url in this form: (
https://leetcode.com/submissions/detail/<submission-id>/
) -
Handle duplicate files (replace, merge, add new)
-
Support Codeforces (and come up with a new repo name :D)