Skip to content

Ismail-Mahmoud/lcws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Web Scraper

Scrape LeetCode and automatically upload your solutions to GitHub.

Installation

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 .

Configuration

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.

LeetCode

Under leetcode section, set the following values:

  1. base_url: LeetCode base URL (set by default)
  2. login_page: LeetCode login page (set by default)
  3. user: Your LeetCode username or email
  4. password: Your LeetCode password

*Your LeetCode credentials is used by the web scraper to login to your account and fetch submissions

GitHub

Under github section, set the following values:

  1. api_base_url: GitHub API base URL (set by default)
  2. access_token: Your GitHub access token*
  3. owner: Your GitHub username
  4. repo: Name of the repo to which the solution will be uploaded
  5. branch: Name of the branch to which the solution will be uploaded
  6. directory: 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.

Usage

Just run the following command:

lcws <URL>

where URL is a valid URL of one of the following:

  1. LeetCode problem (https://leetcode.com/problems/<problem-name>/). In this case, the last accepted submission will be fetched.
  2. LeetCode submission (https://leetcode.com/problems/<problem-name>/submissions/<submission-id>/).

For help, run:

lcws --help

Demo

a

Future Work

  • 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)

About

LeetCode Web Scraper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages