Metadata-Version: 2.4
Name: howlongtobeat-scraper
Version: 0.2.1
Summary: Un scraper para obtener los tiempos de juego desde HowLongToBeat.com.
Home-page: https://github.com/tu_usuario/howlongtobeat_scrapper
Author: Tu Nombre
Author-email: Sermodi <sermodsoftware@gmail.com>
Project-URL: Homepage, https://github.com/Sermodi/HowLongToBeat_scraper
Project-URL: Bug Tracker, https://github.com/Sermodi/HowLongToBeat_scraper/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: playwright
Requires-Dist: beautifulsoup4
Requires-Dist: lxml
Dynamic: license-file

# HowLongToBeat Scraper

A Python package to get game completion times from [HowLongToBeat](https://howlongtobeat.com).

This package provides both a command-line tool and a Python API to look up a game and retrieve its estimated times for main story, extras, and 100% completion.

## Features

-   **Command-Line Interface (CLI)**: Get game times directly from your terminal.
-   **Python API**: Easily integrate HowLongToBeat functionality into your own Python scripts.
-   **Asynchronous**: Built on `asyncio` and `playwright` for efficient performance.
-   **Structured Data**: Returns data in a `dataclass` for easy access.

## Installation

### From PyPI (Recommended)

Install the package from the official Python Package Index:

```bash
pip install howlongtobeat-scraper
```

After installation, you may need to install Playwright browsers:

```bash
playwright install
```

### From TestPyPI (Development)

For testing purposes, you can also install from TestPyPI:

```bash
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple howlongtobeat-scraper
playwright install
```

### From Source (for Development)

If you want to contribute or install the latest development version, you can clone the repository and install it in editable mode:

```bash
git clone https://github.com/Sermodi/HowLongToBeat_scraper.git
cd HowLongToBeat_scraper
pip install -e .
```

## Usage

### Command-Line Interface (CLI)

Once installed, you can use the `howlongtobeat` command followed by the game's name.

```bash
howlongtobeat "The Witcher 3: Wild Hunt"
```

If the command is not found in your PATH (a common issue on Windows), you can run the package as a module:

```bash
python -m howlongtobeat_scraper "The Witcher 3: Wild Hunt"
```

**Example Output:**

```
Searching for "The Witcher 3: Wild Hunt"...
Title: The Witcher 3: Wild Hunt
- Main Story: 51.5 hours
- Main + Extras: 103 hours
- Completionist: 172 hours
```

### Python API

Import the `get_game_stats` function to use it in your code. It's a synchronous function that internally manages an `asyncio` event loop for the scraping process.

```python
from __future__ import annotations
from howlongtobeat_scraper.api import get_game_stats, GameData

def main():
    game_name = "Celeste"
    print(f"--- Fetching data for: {game_name} ---")

    try:
        game_data: GameData | None = get_game_stats(game_name)
        if game_data:
            print("API call successful. Data received:")
            print(f"  Title: {game_data.title}")
            print(f"  Main Story: {game_data.main_story} hours")
            print(f"  Main + Extras: {game_data.main_extra} hours")
            print(f"  Completionist: {game_data.completionist} hours")
        else:
            print("No data found for the game.")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()
```

## Spanish Documentation

A Spanish version of this README is available at [README.es.md](README.es.md).
