pip install requests python-dotenv-
Open https://leetcode.com and sign in to your account.
-
Open Developer Tools (
F12) and go to:- Application tab (Chrome)
- Storage tab (Firefox)
-
In the left sidebar, open Cookies →
https://leetcode.com. -
Copy the values of:
LEETCODE_SESSIONcsrftoken
⚠️ Important: These cookies are private authentication credentials. Store them only in your.envfile and never commit them to Git. Make sure.envis included in your.gitignore.
- Go to https://github.com/settings/tokens.
- Click Generate new token (classic).
- Grant the repo permission.
- Copy the generated token and save it in your
.envfile.
cp .env.example .envOpen .env with your preferred editor (VS Code, Nano, Vim, etc.) and fill in the required values.
python leetcode_to_github.pyThe script will automatically:
- Fetch all your solved LeetCode problems (including your solution code).
- Generate your solving statistics.
- Create a
README.md. - Organize solutions into
Difficulty/Topic/folders. - Push everything to your GitHub repository (it will create the repository automatically if it doesn't already exist).
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