Metadata-Version: 2.4
Name: leetcode-sync-cli
Version: 0.1.1
Summary: CLI tool to sync LeetCode submissions into structured Git repository
Author-email: Narendran Murali <narendranmurali2001@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/yourusername/leetcode-sync-cli
Project-URL: Repository, https://github.com/yourusername/leetcode-sync-cli
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: click
Requires-Dist: python-dotenv

![PyPI version](https://img.shields.io/pypi/v/leetcode-sync-cli)
![Python versions](https://img.shields.io/pypi/pyversions/leetcode-sync-cli)
![License](https://img.shields.io/pypi/l/leetcode-sync-cli)

# 🚀 leetcode-sync-cli

> A powerful CLI tool to automatically sync your LeetCode submissions into a clean, structured GitHub repository — with versioning, difficulty grouping, dashboard generation, and optional auto-sync via GitHub Actions.

---

## ✨ Features

- 🔐 Secure credential handling (persistent session storage)
- ✅ Credential validation before syncing
- 🔄 Automatic re-authentication if session expires
- 📂 Organizes problems by difficulty (Easy / Medium / Hard)
- 🧠 Keeps only latest submission per language
- ⚡ Caches problem difficulty for performance
- 📝 Auto-generates README per problem
- 📊 Auto-updates progress dashboard in root README
- 🚀 Optional Git auto-commit & push
- 🤖 Optional GitHub Actions daily auto-sync
- 📦 Installable via pip

---

## 📦 Installation

Install from PyPI:

```bash
pip install leetcode-sync-cli
```
## 🔐 First-Time Setup
On first run, the CLI will prompt for:

- LEETCODE_SESSION
- CSRFTOKEN

You can find these in:

```code
LeetCode → DevTools → Application → Cookies
```

They are stored securely in:
```code
~/.leetcode_sync/.env
```

## 🔄 Basic Usage

Sync your submissions:
```bash
leetcode-sync --sync
```

Sync and push changes to GitHub:
```bash
leetcode-sync --sync --push
```

## 📂 Generated Repository Structure
```code
problems/
├── easy/
│   └── two_sum/
│       ├── solution.py
│       └── README.md
│
├── medium/
│   └── group_anagrams/
│
└── hard/
```
Root README automatically contains:
| Difficulty | Count |
| ---------- | ----- |
| Easy       | 24    |
| Medium     | 38    |
| Hard       | 8     |
| Total      | 70    |

## 🤖 Enable Daily Auto-Sync (Optional)
Generate GitHub Actions workflow:
```bash
leetcode-sync --setup-autosync
```

This creates:
```code
.github/workflows/leetcode-sync.yml
```

Then:
1. Commit & push the workflow
2. Go to GitHub → Settings → Secrets
3. Add:
    - LEETCODE_SESSION
    - CSRFTOKEN
Your repo will now auto-sync daily.

## 🔄 Session Expiration Handling
If your LeetCode session expires:
- The CLI detects invalid credentials
- Prompts for new session
- Updates stored credentials automatically
- Continues execution
No manual cleanup needed.

## ⚙️ Advanced Features
- Automatic difficulty caching
- Graceful Git error handling
- Safe commit (no changes → no crash)
- Clean package architecture
- Compatible with GitHub Actions
- Ready for pipx installation

## 🧠 How It Works
- Uses LeetCode's internal GraphQL API
- Fetches accepted submissions
- Deduplicates by latest per language
- Retrieves difficulty (cached)
- Generates structured folders
- Updates progress dashboard
- Optionally commits and pushes

## 🛡 Security Note
This tool uses your LeetCode session cookie.
- Credentials are never committed
- Stored locally in user config directory
- Not shared externally
- Can be reset anytime by deleting:
```code
~/.leetcode_sync/
```

## 🛠 Development
Clone Repo:
```bash
git clone https://github.com/WixBe/leetcode-sync-cli
cd leetcode-sync-cli
pip install -e .
```
Run locally:
```bash
leetcode-sync --sync
```

## 📈 Roadmap
- Runtime & memory stats in problem README
- Exponential retry/backoff
- Multi-profile support
- Progress badges
- Semantic version automation

## ⭐ Contributing
Contributions are welcome!
Feel free to open issues or submit pull requests.

Built with ❤️ by Narendran
