Skip to content

About

Automatically sync your accepted LeetCode solutions to GitHub with generated README files, organized folders, and repository statistics.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Setup — LeetCode → GitHub Sync

1. Install Dependencies

pip install requests python-dotenv

2. Get Your LEETCODE_SESSION and CSRF_TOKEN

  1. Open https://leetcode.com and sign in to your account.

  2. Open Developer Tools (F12) and go to:

    • Application tab (Chrome)
    • Storage tab (Firefox)
  3. In the left sidebar, open Cookies → https://leetcode.com.

  4. Copy the values of:

    • LEETCODE_SESSION
    • csrftoken

⚠️ Important: These cookies are private authentication credentials. Store them only in your .env file and never commit them to Git. Make sure .env is included in your .gitignore.


3. Generate a GITHUB_TOKEN

  1. Go to https://github.com/settings/tokens.
  2. Click Generate new token (classic).
  3. Grant the repo permission.
  4. Copy the generated token and save it in your .env file.

4. Configure the .env File

cp .env.example .env

Open .env with your preferred editor (VS Code, Nano, Vim, etc.) and fill in the required values.


5. Run the Script

python leetcode_to_github.py

The script will automatically:

  1. Fetch all your solved LeetCode problems (including your solution code).
  2. Generate your solving statistics.
  3. Create a README.md.
  4. Organize solutions into Difficulty/Topic/ folders.
  5. Push everything to your GitHub repository (it will create the repository automatically if it doesn't already exist).

6. Automate the Sync (Optional)

To run the sync automatically every day (for example, at 8:00 AM) using a cron job:

# Add this line to your crontab (crontab -e)
0 8 * * * cd /path/to/leetcode-sync && /usr/bin/python3 leetcode_to_github.py >> sync.log 2>&1

About

Automatically sync your accepted LeetCode solutions to GitHub with generated README files, organized folders, and repository statistics.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages