Metadata-Version: 2.1
Name: bygod
Version: 3.0.1
Summary: A comprehensive, truly asynchronous tool for downloading Bible translations from BibleGateway.com
Author-email: ByGoD Team <ByGoD@rapdirabbit.software>
Maintainer-email: ByGoD Team <ByGoD@rapdirabbit.software>
License: MIT
Project-URL: Homepage, https://github.com/Christ-Is-The-King/bygod
Project-URL: Documentation, https://github.com/Christ-Is-The-King/bygod#readme
Project-URL: Repository, https://github.com/Christ-Is-The-King/bygod
Project-URL: Bug Tracker, https://github.com/Christ-Is-The-King/bygod/issues
Keywords: bible,download,biblegateway,async,scripture,religion,json,csv,xml,yaml
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Religion
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup :: HTML
Classifier: Topic :: Utilities
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.8.0
Requires-Dist: beautifulsoup4>=4.11.0
Requires-Dist: colorlog>=6.7.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: lxml>=4.9.0
Requires-Dist: meaningless>=1.2.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pylint; extra == "dev"
Requires-Dist: bandit; extra == "dev"
Requires-Dist: pydocstyle; extra == "dev"
Requires-Dist: vulture; extra == "dev"
Requires-Dist: radon; extra == "dev"
Requires-Dist: safety; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: build; extra == "dev"

# ByGoD

A comprehensive, truly asynchronous tool for downloading Bible translations from BibleGateway.com in multiple formats (JSON, CSV, YAML, XML) with genuine parallel downloads, retry mechanisms, and flexible output options.

## 🚀 Features

- **True Async HTTP Requests**: Uses `aiohttp` for genuine parallelism, not just threading
- **Direct HTML Parsing**: Bypasses synchronous libraries to directly parse BibleGateway HTML
- **Multiple Translations**: Support for 30+ Bible translations (NIV, KJV, ESV, etc.)
- **Multiple Formats**: Output in JSON, CSV, YAML, and XML formats
- **Intelligent Rate Limiting**: Configurable concurrency with automatic rate limiting
- **Retry Mechanisms**: Exponential backoff with configurable retry attempts
- **Organized Output**: Structured directory organization by translation and format
- **Comprehensive Logging**: Colored, detailed progress tracking
- **Flexible Output Modes**: Download individual books, full Bibles, or both

## 📦 Installation

### Option 1: Install from PyPI (Recommended)

```bash
pip install bygod
```

### Option 2: Install from Source (Using Pipenv)

1. **Clone the repository**:
   ```bash
   git clone git@github.com:Christ-Is-The-King/bygod.git
   cd bygod
   ```

2. **Install pipenv** (if not already installed):
   ```bash
   pip install pipenv
   ```

3. **Install dependencies and activate virtual environment**:
   ```bash
   pipenv install
   pipenv shell
   ```

4. **Install in development mode**:
   ```bash
   pip install -e .
   ```

5. **Run the application**:
   ```bash
   python main.py [options]
   ```

### Option 3: Install from Source (Using pip)

1. **Clone the repository**:
   ```bash
   git clone git@github.com:Christ-Is-The-King/bygod.git
   cd bygod
   ```

2. **Create a virtual environment**:
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   ```

3. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

4. **Install in development mode**:
   ```bash
   pip install -e .
   ```

### Option 4: Build and Install Package

1. **Build the package**:
   ```bash
   python build_package.py
   ```

2. **Install the built package**:
   ```bash
   pip install dist/bygod-*.whl
   ```

## 🎯 Quick Start

### Basic Usage

Download a single translation in JSON format:
```bash
bygod --translations NIV --formats json
```

Download multiple translations in multiple formats:
```bash
bygod --translations NIV,KJV,ESV --formats json,csv,xml
```

Download specific books only:
```bash
bygod --translations NIV --books Genesis,Exodus,Psalms
```

### Advanced Usage

Download with custom rate limiting and retry settings:
```bash
bygod \
  --translations NIV,KJV \
  --formats json,csv \
  --rate-limit 10 \
  --retries 5 \
  --retry-delay 3 \
  --timeout 600
```

Download only individual books (no full Bible):
```bash
bygod --translations NIV --output-mode books
```

Download only full Bible (no individual books):
```bash
bygod --translations NIV --output-mode book
```

### Verbosity and Logging

Control output verbosity and error logging:

- Use `-v`, `-vv`, or `-vvv` for increasing verbosity
- Use `-q` or `--quiet` to suppress all output except errors
- Use `-e` or `--log-errors` to log errors to a file
- Use `-l` or `--log-level` to set the logging level

**Verbose mode (more detailed output):**

```
bygod --translations NIV --output-mode books -v
```

**Log errors to file:**

```
bygod --translations NIV --log-errors logs/bible_errors.log
```

**Set specific log level:**

```
bygod --translations NIV --log-level DEBUG
```

**Combine options:**

```
bygod --translations NIV -v --log-errors logs/errors.log --log-level WARNING
```

---

## 📋 Sample Log Output

Example log lines for chapter and book downloads:

```
✅ Downloaded Psalms 149 (NIV): 9 verses in 2.3s
✅ Downloaded Psalms 150 (NIV): 6 verses in 1.1s
📊 Completed Psalms (NIV): 150/150 chapters, 2,385 total verses in 1m 57.6s
```

- Each chapter log shows the number of verses and the time taken for that chapter.
- The book completion log shows the total chapters, total verses (comma-formatted), and the total time for the book.

## 📋 Command Line Options

| Option | Description | Default |
|--------|-------------|---------|
| `--translations` | Comma-separated list of Bible translations | `NIV` |
| `--formats` | Output formats: json, csv, xml, yaml | `json` |
| `--output-mode` | Output mode: book, books, all | `all` |
| `--output-dir` | Directory to save downloaded Bibles | `./bibles` |
| `--rate-limit` | Maximum concurrent requests | `5` |
| `--retries` | Maximum retry attempts | `3` |
| `--retry-delay` | Delay between retries (seconds) | `2` |
| `--timeout` | Request timeout (seconds) | `300` |
| `--books` | Comma-separated list of specific books | All books |
| `-v, --verbose` | Increase verbosity level (-v for INFO, -vv for DEBUG) | `0` |
| `-q, --quiet` | Suppress all output except errors | `False` |
| `--log-level` | Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) | `INFO` |
| `--log-errors` | Log errors to specified file in clean format | `None` |

## 📚 Supported Translations

The downloader supports 30+ Bible translations including:

- **NIV** - New International Version
- **KJV** - King James Version
- **ESV** - English Standard Version
- **NKJV** - New King James Version
- **NLT** - New Living Translation
- **CSB** - Christian Standard Bible
- **NASB** - New American Standard Bible
- **RSV** - Revised Standard Version
- **ASV** - American Standard Version
- **WEB** - World English Bible
- **YLT** - Young's Literal Translation
- **AMP** - Amplified Bible
- **MSG** - The Message
- **CEV** - Contemporary English Version
- **ERV** - Easy-to-Read Version
- **GW** - God's Word Translation
- **HCSB** - Holman Christian Standard Bible
- **ICB** - International Children's Bible
- **ISV** - International Standard Version
- **LEB** - Lexham English Bible
- **NCV** - New Century Version
- **NET** - New English Translation
- **NIRV** - New International Reader's Version
- **NRSV** - New Revised Standard Version
- **TLB** - The Living Bible
- **TLV** - Tree of Life Version
- **VOICE** - The Voice
- **WYC** - Wycliffe Bible

## 📁 Output Structure

The downloader creates a well-organized directory structure:

```
bibles/
├── NIV/
│   ├── NIV.json          # Full Bible in JSON
│   ├── NIV.csv           # Full Bible in CSV
│   ├── NIV.xml           # Full Bible in XML
│   ├── NIV.yml           # Full Bible in YAML
│   └── books/
│       ├── Genesis.json  # Individual book in JSON
│       ├── Genesis.csv   # Individual book in CSV
│       ├── Genesis.xml   # Individual book in XML
│       ├── Genesis.yml   # Individual book in YAML
│       └── ...
├── KJV/
│   ├── KJV.json
│   ├── KJV.csv
│   └── books/
│       └── ...
└── ...
```

## 🏗️ Project Structure

The project has been refactored into a clean, modular structure:

```
bygod/
├── main.py                    # Main entry point
├── src/                       # Source code package
│   ├── __init__.py
│   ├── constants/             # Bible translations and books data
│   │   ├── translations.py    # BIBLE_TRANSLATIONS dictionary
│   │   └── books.py          # BOOKS list
│   ├── core/                  # Core downloader functionality
│   │   └── downloader.py      # AsyncBibleDownloader class
│   ├── utils/                 # Utility functions
│   │   ├── formatting.py      # Duration and number formatting
│   │   └── logging.py         # Logging setup and configuration
│   ├── cli/                   # Command line interface
│   │   └── parser.py          # Argument parsing and validation
│   ├── processors/            # Processing logic
│   │   ├── bible_processor.py # Bible download processing
│   │   └── master_processor.py # Master file processing
│   └── utils/                 # Utility functions
│       ├── formatting.py      # Duration and number formatting
│       └── logging.py         # Logging setup and configuration
├── pyproject.toml             # Project configuration
├── README.md                  # This file
└── ... (other files)
```

## 🔧 Technical Details

### True Async Architecture

Unlike traditional threading approaches, this downloader uses:

- **`asyncio`**: Python's native async/await framework
- **`aiohttp`**: True async HTTP client for concurrent requests
- **Semaphores**: Rate limiting with configurable concurrency
- **`asyncio.gather()`**: Parallel execution of multiple downloads

### HTML Parsing

The downloader directly parses BibleGateway HTML using:

- **BeautifulSoup**: HTML parsing and navigation
- **CSS Selectors**: Multiple fallback selectors for verse extraction
- **Regex Patterns**: Chapter discovery and verse number detection

### Modular Architecture

The codebase has been refactored into a clean, modular structure:

- **Separation of Concerns**: Each module has a specific responsibility
- **Maintainability**: Easy to understand and modify individual components
- **Testability**: Each module can be tested independently
- **Reusability**: Core downloader can be imported and used in other projects
- **Code Quality**: Comprehensive linting and formatting standards

### Code Quality Standards

The project maintains high code quality through automated tools:

- **Formatting**: Black for consistent code style, isort for import organization
- **Linting**: Flake8 for style guide enforcement, Pylint for code analysis
- **Type Checking**: MyPy for static type analysis
- **Security**: Bandit for security vulnerability detection, Safety for dependency scanning
- **Documentation**: Pydocstyle for docstring standards
- **Complexity**: Vulture for dead code detection, Radon for complexity analysis

All code is automatically formatted and follows PEP 8 standards.

### Error Handling

- **Exponential Backoff**: Intelligent retry with increasing delays
- **Rate Limit Detection**: Automatic handling of 429 responses
- **Graceful Degradation**: Continues processing even if some downloads fail
- **Detailed Logging**: Comprehensive error reporting and progress tracking

## 🧪 Testing

Run the test suite to verify functionality:

```bash
# Using pipenv
pipenv run python -m pytest src/tests/ -v

# Run specific test categories
pipenv run python -m pytest src/tests/test_constants.py -v
pipenv run python -m pytest src/tests/test_utils.py -v
pipenv run python -m pytest src/tests/test_core.py -v

# Run with coverage
pipenv run python -m pytest src/tests/ --cov=src --cov-report=html
```

The test suite includes:
- **Core Functionality**: Downloader initialization, context management, request handling
- **Constants Validation**: Bible translations, books, and chapter counts
- **Utilities**: Formatting functions and logging setup
- **Integration Tests**: End-to-end download scenarios

### Test Results
- **47 tests passed** ✅
- **1 test skipped** ⏭️ (complex async mocking)
- **0 tests failed** ❌
- **Clean test suite**: Removed problematic network simulation tests

## 📊 Performance

The true async architecture provides significant performance improvements:

- **Genuine Parallelism**: Multiple HTTP requests execute simultaneously
- **Efficient Resource Usage**: No thread overhead, uses event loop
- **Scalable Concurrency**: Configurable rate limits prevent server overload
- **Memory Efficient**: Streams responses without loading entire files into memory

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Install dependencies using pipenv:
   ```bash
   pipenv install
   pipenv install --dev
   ```
4. Make your changes
5. Add tests for new functionality
6. Ensure all tests pass:
   ```bash
   pipenv run python tests.py
   ```
7. Run the linter to ensure code quality:
   ```bash
   # Run all code quality checks
   ./scripts/code-checker.sh --all
   
   # Or run specific checks
   ./scripts/code-checker.sh --format  # Black + isort
   ./scripts/code-checker.sh --lint    # Flake8 + Pylint
   ./scripts/code-checker.sh --type    # MyPy type checking
   ./scripts/code-checker.sh --security # Bandit + Safety
   ```
8. Submit a pull request

## 📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

## 🙏 Acknowledgments

- BibleGateway.com for providing Bible content
- The Python async community for excellent tools and documentation
- Contributors and users who provide feedback and improvements

## 🆘 Troubleshooting

### Common Issues

**Rate Limiting**: If you encounter 429 errors, reduce the `--rate-limit` value.

**Timeout Errors**: Increase the `--timeout` value for slower connections.

**Missing Verses**: Some translations may have different HTML structures. The parser includes multiple fallback methods.

**Memory Usage**: For large downloads, consider downloading fewer books at once or using a lower rate limit.

### Getting Help

- Check the logs for detailed error messages
- Try with a single translation and book first
- Ensure your internet connection is stable
- Verify that BibleGateway.com is accessible from your location 
