This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
算法学习助手 (Code Learning Agent) - A comprehensive tool suite for algorithm learning that integrates problem scraping and learning statistics. The project consists of three main modules:
- luogu_scraper: Scrapes Luogu problem sets, problems, and solutions
- leetcode_scraper: Scrapes LeetCode problems and solutions
- stats: Generates learning statistics and progress analysis
cd luogu_scraper
# Install dependencies
pip install -r requirements.txt
# Scrape all official problem sets
python main.py
# Scrape specific problem set by ID
python main.py --training-id 1
# Scrape single problem
python main.py --problem P1001
# Scrape without solutions
python main.py --problem P1001 --no-solutions
# Adjust request delay (avoid rate limiting)
python main.py --training-id 1 --delay 2.0
# Get more solutions per problem
python main.py --problem P1001 --solutions-limit 5cd leetcode_scraper
# Install dependencies
pip install -r requirements.txt
# List problems
python main.py --list
# List with limit
python main.py --list --list-limit 20
# Filter by difficulty
python main.py --list --difficulty medium
# Scrape specific problem by slug
python main.py --problem two-sum
# Scrape by problem ID
python main.py --problem-id 146
# Use China site (leetcode.cn)
python main.py --problem two-sum --cn
# NEW: List available problem sources
python main.py --list-sources
# NEW: Scrape problem lists for learning plans
python main.py --scrape-list study-plan:top-interview-150
python main.py --scrape-list company:google --limit 200
python main.py --scrape-list topic:dynamic-programming --limit 100
python main.py --scrape-list difficulty:easy --limit 50
python main.py --scrape-list high-frequency --limit 100
# Save to specific file
python main.py --scrape-list study-plan:leetcode-75 --output-list ../stats/data/leetcode75.jsoncd stats
# Create a learning plan
python create_plan.py \
--name "Interview Prep" \
--source study-plan:top-interview-150 \
--start 2026-02-01 \
--end 2026-03-02 \
--difficulty-progression \
--topic-balancing
# List all learning plans
python view_plan.py --list
# View specific plan
python view_plan.py --plan plan_001
# View today's problems
python view_plan.py --plan plan_001 --today
# View progress
python view_plan.py --plan plan_001 --progress
# Export plan to Markdown
python view_plan.py --plan plan_001 --export my_plan.md
# Delete a plan
python view_plan.py --plan plan_001 --delete
# Mark problem as learned (auto-updates plan progress)
python mark_learned.py 1 "Two Sum - Hash table approach"cd stats
# Generate statistics
python generate_stats.py
# View statistics summary
cat data/stats.json | jq '.summary'
# Mark problems as learned
python mark_learned.py
# Start web server to view stats
python serve.pyThe project follows a modular architecture with three independent scrapers:
luogu_scraper/
main.py: Entry point and orchestrationtraining_scraper.py: Handles problem set scrapingproblem_scraper.py: Handles individual problem scrapingsolution_scraper.py: Handles solution scrapingutils.py: Shared utilities (LuoguSession, file operations)config.py: Configuration (API URLs, headers, delays, cookie)
leetcode_scraper/
main.py: Entry point and orchestrationproblem_scraper.py: Handles problem scraping via GraphQL APIsolution_scraper.py: Handles solution scrapinglist_scraper.py: NEW - Scrapes problem lists (study plans, companies, topics, difficulty)utils.py: Shared utilities (LeetCodeSession, file operations)config.py: Configuration (API endpoints, delays, cookie, problem sources)
stats/
generate_stats.py: Main statistics generation script (includes learning plan stats)mark_learned.py: Helper to mark problems as learned (auto-updates learning plans)serve.py: Web server for viewing statisticsscheduler.py: NEW - Intelligent problem scheduling algorithmplan_manager.py: NEW - Learning plan CRUD operationscreate_plan.py: NEW - CLI tool to create learning plansview_plan.py: NEW - CLI tool to view and manage learning plansdata/learning_record.json: Tracks learned problems and daily progressdata/learning_plan.json: NEW - Stores learning plans and schedulesdata/stats.json: Generated statistics output (includes plan stats)templates/plan_template.md: NEW - Markdown template for plan export
- Scraping: Scrapers fetch data from Luogu/LeetCode APIs and save to
output/directories - Learning: User manually updates
stats/data/learning_record.jsonafter completing problems - Statistics:
generate_stats.pyscans problem files and merges with learning records to generate comprehensive statistics - Learning Plans (NEW):
- List Scraping: Use
leetcode_scraper/list_scraper.pyto fetch problem lists from various sources - Plan Creation:
create_plan.pyusesscheduler.pyto intelligently distribute problems across dates - Progress Tracking:
mark_learned.pyautomatically updates plan progress when problems are marked as learned - Plan Management:
plan_manager.pyhandles CRUD operations and progress calculations
- List Scraping: Use
Both scrapers use session classes (LuoguSession, LeetCodeSession) that:
- Manage HTTP requests with proper headers
- Handle rate limiting with configurable delays
- Support cookie-based authentication
- Implement retry logic for failed requests
Problems are saved in dual format:
- JSON: Structured data for programmatic access
- Markdown: Human-readable format for review
Directory structure:
output/
├── trainings/
│ └── {id}_{title}/
│ ├── training_info.json
│ └── problems/
│ └── {pid}/
│ ├── problem.json
│ ├── problem.md
│ ├── solutions.json
│ ├── solution_1.md
│ ├── solution_2.md
│ └── solution_3.md
└── problems/
└── {id}_{slug}/
├── problem.json
├── problem.md
├── solutions.json
└── solution_*.md
Luogu requires authentication for most content. To configure:
- Login to https://www.luogu.com.cn
- Open browser DevTools (F12) → Network tab
- Refresh page and select any request
- Copy the Cookie header value
- Edit
luogu_scraper/config.py:COOKIE = '_uid=xxx; __client_id=xxx; ...'
Only needed for premium problems. Same process as Luogu but for leetcode.com or leetcode.cn.
The stats/data/learning_record.json file tracks progress:
{
"learned_problems": {
"P1001": {
"learned_at": "2024-01-15",
"notes": "简单的A+B问题"
}
},
"daily_learning": {
"2024-01-15": ["P1001"],
"2024-01-16": ["P1002", "P1003"]
}
}This project includes Claude Code skills in .claude/skills/:
code-learning-agent.md: Main skill that orchestrates all functionalityluogu-scraper.md: Luogu-specific operationsleetcode-scraper.md: LeetCode-specific operationslearning-stats.md: Statistics generation
Users can invoke these with natural language like:
- "爬取洛谷题单1"
- "获取LeetCode的two-sum题目"
- "生成学习统计"
Both scrapers implement delays to avoid overwhelming servers:
- Default delay: 1.5s for Luogu, 1.0s for LeetCode
- Adjust with
--delayparameter if encountering 403 errors - Respect website terms of service
- 403 errors usually indicate: expired cookie, rate limiting, or IP ban
- Scrapers continue on individual failures and report errors in summary
- Check
DEBUG = Truein config.py for detailed logging
All scraped data is for personal learning only. Do not use for commercial purposes or redistribute.
The stats module:
- Scans
luogu_scraper/examples/categories/for problem files - Reads
learning_record.jsonfor completion status - Generates comprehensive statistics including:
- Overall progress (total/learned/percentage)
- Per-category breakdown
- Tag distribution
- Difficulty distribution
- Daily learning trends
- Scrape problems:
cd luogu_scraper && python main.py --training-id 1 - Study problems: Review generated markdown files
- Complete problems: Write and test solutions
- Record progress: Update
stats/data/learning_record.json - View progress:
cd stats && python generate_stats.py
- Generate statistics to identify weak areas
- Focus on underrepresented tags or difficulties
- Review previously completed problems
- Update learning records
The learning plan feature allows users to create personalized study schedules from LeetCode problem lists with intelligent problem distribution.
- Official Study Plans: Top Interview 150, LeetCode 75, SQL 50, etc.
- Company Lists: Google, Amazon, Microsoft, Facebook, Apple, etc.
- Topic Collections: Dynamic Programming, Trees, Graphs, Arrays, etc.
- Difficulty-Based: Easy, Medium, Hard
- High-Frequency: Problems sorted by likes/popularity
Step 1: Scrape Problem List
cd leetcode_scraper
# List available sources
python main.py --list-sources
# Scrape a study plan
python main.py --scrape-list study-plan:top-interview-150
# Scrape company problems
python main.py --scrape-list company:google --limit 200
# Scrape topic problems
python main.py --scrape-list topic:dynamic-programming --limit 100Step 2: Create Learning Plan
cd stats
python create_plan.py \
--name "Interview Prep" \
--source study-plan:top-interview-150 \
--start 2026-02-01 \
--end 2026-03-02 \
--difficulty-progression \
--topic-balancing \
--skip-learned \
--prioritize-frequencyConfiguration Options:
--difficulty-progression: Easy → Medium → Hard progression (default: enabled)--topic-balancing: Avoid consecutive same-topic problems (default: enabled)--skip-learned: Skip already completed problems (default: enabled)--prioritize-frequency: Prioritize high-frequency problems (default: enabled)--problems-per-day N: Set specific daily problem count (default: auto-calculated)
The intelligent scheduler uses a composite scoring system:
Scoring Weights:
- Frequency Score (40%): Based on problem likes count
- Difficulty Score (30%): Prioritizes easier problems first
- Topic Diversity (30%): Ensures varied problem types
Distribution Strategy:
- Filter out already learned problems (if enabled)
- Calculate composite score for each problem
- Sort by score (high-frequency, easy problems first)
- Distribute across dates with topic balancing
- Avoid consecutive problems with overlapping tags
View All Plans:
python view_plan.py --list
python view_plan.py --list --status activeView Plan Details:
python view_plan.py --plan plan_001View Today's Problems:
python view_plan.py --plan plan_001 --todayView Progress:
python view_plan.py --plan plan_001 --progressExport to Markdown:
python view_plan.py --plan plan_001 --export my_plan.mdDelete Plan:
python view_plan.py --plan plan_001 --deleteWhen you mark a problem as learned, the system automatically updates all active learning plans:
python mark_learned.py 1 "Two Sum - Hash table approach"Output:
✅ 已标记 1 为已学习
日期: 2026-01-29
笔记: Two Sum - Hash table approach
📋 已更新学习计划:
- Interview Prep
The system tracks:
- Completion Rate: Percentage of problems completed
- Days Elapsed/Remaining: Time tracking
- On-Track Status: Whether you're ahead or behind schedule
- Expected vs Actual: Comparison of expected and actual progress
- Ahead/Behind: Number of problems ahead or behind schedule
Workflow 1: Interview Preparation (30 days)
# 1. Scrape Top Interview 150
cd leetcode_scraper
python main.py --scrape-list study-plan:top-interview-150
# 2. Create 30-day plan
cd ../stats
python create_plan.py \
--name "Interview Prep - 30 Days" \
--source study-plan:top-interview-150 \
--start 2026-02-01 \
--end 2026-03-02 \
--difficulty-progression \
--topic-balancing
# 3. Daily routine
python view_plan.py --plan plan_001 --today # View today's problems
# ... solve problems ...
python mark_learned.py 1 "Completed" # Mark as learned
python view_plan.py --plan plan_001 --progress # Check progress
# 4. Weekly review
python view_plan.py --plan plan_001 --export week1.md
python generate_stats.py # Generate overall statisticsWorkflow 2: Company-Specific Preparation
# 1. Scrape Google problems
cd leetcode_scraper
python main.py --scrape-list company:google --limit 200
# 2. Create plan with high-frequency priority
cd ../stats
python create_plan.py \
--name "Google Interview Prep" \
--source company:google \
--start 2026-02-01 \
--end 2026-03-15 \
--prioritize-frequency \
--limit 200
# 3. Focus on high-frequency problems first
python view_plan.py --plan plan_002 --todayWorkflow 3: Topic Mastery
# 1. Scrape Dynamic Programming problems
cd leetcode_scraper
python main.py --scrape-list topic:dynamic-programming --limit 100
# 2. Create focused plan
cd ../stats
python create_plan.py \
--name "DP Mastery" \
--source topic:dynamic-programming \
--start 2026-02-01 \
--end 2026-02-28 \
--difficulty-progression \
--limit 100
# 3. Systematic learning
python view_plan.py --plan plan_003 --todaylearning_plan.json Structure:
{
"plans": {
"plan_001": {
"id": "plan_001",
"name": "Interview Prep",
"source": "top-interview-150",
"start_date": "2026-02-01",
"end_date": "2026-03-02",
"total_problems": 150,
"problem_list": [...],
"schedule": {
"2026-02-01": {
"problem_ids": ["1", "20", "21"],
"completed_count": 0,
"total_count": 3
}
},
"progress": {
"completed_problems": 0,
"completion_rate": 0.0,
"on_track": true
}
}
}
}- Automatic Progress Updates:
mark_learned.pyupdates plan progress - Statistics Integration:
generate_stats.pyincludes plan statistics - Learning Records: Plans respect existing
learning_record.json - Skip Learned: Plans automatically filter out completed problems
- Start with Easy Plans: Begin with smaller problem sets (50-75 problems) to build momentum
- Adjust Daily Load: Use
--problems-per-dayto match your schedule - Review Regularly: Check progress weekly to stay on track
- Export Plans: Use
--exportto create printable study guides - Multiple Plans: You can have multiple active plans for different goals
- Flexible Scheduling: Plans adapt to your actual completion rate