87 lines
2.2 KiB
Markdown
87 lines
2.2 KiB
Markdown
---
|
|
name: leetcode-daily-card
|
|
description: A Python script that automatically fetches the daily LeetCode challenge and renders it as a PNG card or Markdown document.
|
|
metadata: {"clawdbot":{"emoji":"📋","os":["linux","darwin","win32"]}}
|
|
---
|
|
|
|
# LeetCode Daily Card Generator
|
|
|
|
A Python script that automatically fetches the daily LeetCode challenge and renders it as a PNG card or Markdown document.
|
|
|
|
## Features
|
|
|
|
- **Automatic Daily Fetch**: Retrieves the current daily LeetCode problem via GraphQL API
|
|
- **Two-Step Rendering**: HTML → Markdown → PNG for optimal text rendering
|
|
- **CJK Support**: Uses system CJK fonts (Microsoft YaHei, SimHei, etc.) for Chinese characters
|
|
- **Multiple Output Formats**: Supports `.png` for image cards and `.md` for Markdown documents
|
|
- **Clean Unicode Handling**: Removes zero-width spaces and other invisible Unicode characters
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install Pillow html2text
|
|
```
|
|
|
|
## Dependencies
|
|
|
|
- **Pillow**: For PNG/JPG image rendering
|
|
- **html2text**: For converting HTML content to Markdown
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
# Generate PNG card
|
|
python scripts/run.py output.png
|
|
|
|
# Generate Markdown document
|
|
python scripts/run.py output.md
|
|
```
|
|
|
|
## Output Formats
|
|
|
|
### PNG Card
|
|
- Blue gradient header
|
|
- White card body with rounded corners
|
|
- Dark gradient background
|
|
- Displays: title, question ID, difficulty, acceptance rate, tags, description
|
|
|
|
### Markdown Document
|
|
- Clean Markdown formatting
|
|
- Question metadata in Info section
|
|
- Full problem description
|
|
- Example test cases
|
|
- Link to problem page
|
|
|
|
## Supported Platforms
|
|
|
|
- **Windows**: Uses `msyh.ttc` (Microsoft YaHei), `simhei.ttf`, etc.
|
|
- **macOS**: Uses PingFang.ttc, STHeiti Light.ttc
|
|
- **Linux**: Uses NotoSansCJK, DejaVuSans.ttf, wqy-microhei.ttc
|
|
|
|
## Workflow
|
|
|
|
```
|
|
LeetCode API (HTML)
|
|
↓
|
|
html2text (Markdown)
|
|
↓
|
|
Markdown → Plain Text (cleanup)
|
|
↓
|
|
Pillow (PNG Image)
|
|
```
|
|
|
|
## Example
|
|
|
|
```bash
|
|
python scripts/run.py daily.png
|
|
# Output: daily.png with the daily LeetCode challenge card
|
|
|
|
python scripts/run.py daily.md
|
|
# Output: daily.md with formatted Markdown content
|
|
```
|
|
|
|
## Notes
|
|
|
|
- The script requires internet access to fetch from LeetCode API
|
|
- Formula rendering is not supported (plain text only)
|
|
- Chinese fonts must be installed on the system for CJK character display |