An automated system for downloading, analyzing, and reporting on criminal law opinions from all 14 Texas Courts of Appeals using Claude AI for legal analysis.
- Automated Opinion Downloading: Scrapes all 14 Texas Courts of Appeals for criminal opinions
- AI-Powered Legal Analysis: Uses Claude 4 Sonnet to identify interesting legal issues
- Professional PDF Reports: Generates comprehensive reports with direct links to court opinions
- Error Detection & Retry: Robust downloading with retry logic and error handling
- Database Storage: SQLite database for tracking opinions, analyses, and metadata
- Flexible Execution: Multiple modes for scraping, analysis, and reporting
The system identifies:
- Novel or controversial legal questions
- Cases relying on pre-2000 Court of Criminal Appeals precedent
- Logical errors in court reasoning (category errors, internal contradictions, circular reasoning)
- Emerging legal doctrines and unsettled law
- Direct PDF Links: Clickable links to original court opinion PDFs
- Case Details: Court, date, case number, and issue count
- Full Analysis: Complete Claude analysis with legal reasoning
- Professional Formatting: Clean, organized PDF reports
-
Clone the repository:
git clone <repository-url> cd Scrape_COA_Opinions
-
Create virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
- Copy
.envand add your Claude API key:
CLAUDE_API_KEY=your_claude_api_key_here
- Copy
# Download and analyze today's opinions (default)
python pdrbot.py
# Download opinions only
python pdrbot.py scrape
# Analyze existing unanalyzed opinions
python pdrbot.py analyze
# Analyze specific number of opinions
python pdrbot.py analyze 10
# Download + analyze everything
python pdrbot.py both
# Generate PDF report from analyses
python pdrbot.py report
# Generate report for specific date
python pdrbot.py report 2025-07-24
# Generate today's daily report
python pdrbot.py daily-report
# Update existing records with direct PDF URLs
python pdrbot.py backfill-urlsEdit .env file to customize:
# Claude API settings
CLAUDE_API_KEY=your_key_here
CLAUDE_MODEL=claude-3-7-sonnet-20250219
CLAUDE_MAX_TOKENS=64000
# Network settings
REQUEST_TIMEOUT=30
MAX_RETRIES=3
DOWNLOAD_DELAY=1
COURT_DELAY=2
# Analysis settings
ANALYSIS_ENABLED=true
AUTO_GENERATE_REPORTS=true
# Courts to scrape (1-14)
COURTS=1,2,3,4,5,6,7,8,9,10,11,12,13,14├── pdrbot.py # Main application
├── scraper.py # Legacy scraper (deprecated)
├── pdrbot-prompt # Legal analysis prompt for Claude
├── .env # Environment configuration
├── requirements.txt # Python dependencies
├── data/ # Downloaded opinions and reports
│ ├── YYYYMMDD/ # Daily opinion folders
│ ├── pdrbot.db # SQLite database
│ └── *.pdf # Generated reports
└── README.md # This file
- Case metadata, file paths, and direct PDF URLs
- Tracks court, date, case number, opinion type
- Links to original court opinion PDFs
- Claude AI analysis results
- Interesting issue flags and counts
- Analysis timestamp and model used
- Execution tracking and statistics
- Success/failure monitoring
The system uses a sophisticated prompt (pdrbot-prompt) that instructs Claude to identify:
- Novel Legal Issues: Controversial or unsettled legal questions
- Pre-2000 Precedent: Cases relying on outdated Court of Criminal Appeals authority
- Logical Errors: Flawed reasoning, category errors, contradictions
- Emerging Doctrines: New or evolving legal principles
Generated PDF reports include:
- Summary Statistics: Total cases, issues found, generation date
- Case-by-Case Analysis: Detailed breakdown with full Claude analysis
- Direct Links: Clickable URLs to original court opinion PDFs
- Professional Formatting: Clean layout with proper pagination
- Retry Logic: 3 attempts with exponential backoff for downloads
- PDF Validation: Checks file integrity and PDF magic bytes
- Network Resilience: Handles timeouts, connection errors
- Database Integrity: Transaction safety and error recovery
For daily automation, add to crontab:
# Run at 12:01 AM daily (Tuesday-Saturday for Monday-Friday opinions)
1 0 * * 2-6 cd /path/to/Scrape_COA_Opinions && ./.venv/bin/python pdrbot.py2025-07-25 06:42:10,872 - INFO - Daily scrape completed!
2025-07-25 06:42:10,872 - INFO - Courts checked: 14
2025-07-25 06:42:10,873 - INFO - Total cases found: 62
2025-07-25 06:42:10,873 - INFO - Total files downloaded: 62
2025-07-25 07:28:49,436 - INFO - Completed analysis for 01-23-00771-CR
2025-07-25 07:28:49,752 - INFO - Saved analysis for 01-23-00771-CR
2025-07-25 07:28:51,753 - INFO - Analysis batch complete: 1 processed, 0 failed
2025-07-25 07:44:00,778 - INFO - Analysis report generated: data/analysis_report_20250725_074400.pdf
Report generated: data/analysis_report_20250725_074400.pdf
- Python 3.8+
- Claude API key (Anthropic)
- Internet connection for court website access
- ~1GB storage for daily opinions (varies by volume)
This tool is for legal research and educational purposes. Always verify information against official court records. The AI analysis is supplementary and should not replace professional legal judgment.
- Fork the repository
- Create a feature branch
- Make changes with appropriate tests
- Submit a pull request
[Add your license information here]
For issues or questions:
- Check the logs in the output
- Verify your
.envconfiguration - Ensure Claude API key is valid
- Review network connectivity
- Added Claude AI analysis integration
- Implemented PDF report generation with direct links
- Enhanced error handling and retry logic
- Added comprehensive database schema
- Streaming support for long Claude requests
- Basic opinion downloading
- Simple file organization
- Manual analysis required