howlongtobeatpy


Namehowlongtobeatpy JSON
Version 1.0.14 PyPI version JSON
download
home_pagehttps://github.com/ScrappyCocco/HowLongToBeat-PythonAPI
SummaryA Python API for How Long to Beat
upload_time2024-12-10 14:21:00
maintainerNone
docs_urlNone
authorScrappyCocco
requires_pythonNone
licenseMIT
keywords howlongtobeat gaming steam uplay origin time length how long to beat
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # HowLongToBeat Python API

[![Python Test Released Published Version](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/python-test-release.yml/badge.svg)](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/python-test-release.yml)
[![CodeQL](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/codeql-analysis.yml)

[![codecov](https://codecov.io/gh/ScrappyCocco/HowLongToBeat-PythonAPI/branch/master/graph/badge.svg)](https://codecov.io/gh/ScrappyCocco/HowLongToBeat-PythonAPI)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=ScrappyCocco_HowLongToBeat-PythonAPI&metric=bugs)](https://sonarcloud.io/dashboard?id=ScrappyCocco_HowLongToBeat-PythonAPI)

A simple Python API to read data from howlongtobeat.com.

It is inspired by [ckatzorke - howlongtobeat](https://github.com/ckatzorke/howlongtobeat) JS API.

## Content

- [Usage](#usage)
- [Installation](#installation)
  - [Installing the package downloading the last release](#installing-the-package-downloading-the-last-release)
  - [Installing the package from the source code](#installing-the-package-from-the-source-code)
- [Usage in code](#usage-in-code)
  - [Start including it in your file](#start-including-it-in-your-file)
  - [Now call search()](#now-call-search)
  - [Alternative search (by ID)](#alternative-search-by-id)
  - [DLC search](#dlc-search)
  - [Results auto-filter](#results-auto-filter)
  - [Reading an entry](#reading-an-entry)
- [Issues, Questions & Discussions](#issues-questions--discussions)
- [Authors](#authors)
- [License](#license)

## Usage

## Installation

### Installing the package downloading the last release

```python
pip install howlongtobeatpy
```

### Installing the package from the source code

Download the repo, enter the folder with 'setup.py' and run the command

```python
pip install .
```

## Usage in code

### Start including it in your file

```python
from howlongtobeatpy import HowLongToBeat
```

### Now call search()

The API main functions are:

```python
results = HowLongToBeat().search("Awesome Game")
```

or, if you prefer using async:

```python
results = await HowLongToBeat().async_search("Awesome Game")
```

The return of that function is a **list** of possible games, or **None** in case you passed an invalid "game name" as parameter or if there was an error in the request.

If the list **is not None** you should choose the best entry checking the Similarity value with the original name, example:

```python
results_list = await HowLongToBeat().async_search("Awesome Game")
if results_list is not None and len(results_list) > 0:
    best_element = max(results_list, key=lambda element: element.similarity)
```

Once done, "best_element" will contain the best game found in the research.
Every entry in the list (if not None in case of errors) is an object of type: [HowLongToBeatEntry](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py).

### Alternative search (by ID)

If you prefer, you can get a game by ID, this can be useful if you already have the game's howlongtobeat-id (the ID is the number in the URL, for example in [https://howlongtobeat.com/game/7231]([hello](https://howlongtobeat.com/game/7231)) the ID is 7231).

To avoid a new parser, the search by ID use a first request to get the game title, and then use the standard search with that title, filtering the results and returning the unique game with that ID.

Remember that it could be a bit slower, but you avoid searching the game in the array by similarity.

Here's the example:

```python
result = HowLongToBeat().search_from_id(123456)
```

or, if you prefer using async:

```python
result = await HowLongToBeat().async_search_from_id(123456)
```

This call will return an unique [HowLongToBeatEntry](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py) or None in case of errors.

### DLC search

An `enum` has been added to have a filter in the search:

```python
SearchModifiers.NONE # default
SearchModifiers.ISOLATE_DLC
SearchModifiers.HIDE_DLC
```

This optional parameter allow you to specify in the search if you want the default search (with DLCs), to HIDE DLCs and only show games, or to ISOLATE DLCs (show only DLCs).

### Results auto-filter

To ignore games with a very different name, the standard search automatically filter results with a game name that has a similarity with the given name > than `0.4`, not adding the others to the result list.
If you want all the results, or you want to change this value, you can put a parameter in the constructor:

```python
results = HowLongToBeat(0.0).search("Awesome Game")
```

putting `0.0` (or just `0`) will return all the found games, otherwise you can write another (`float`) number between 0...1 to set a new filter, such as `0.7`.

Also remember that by default the similarity check **is case-sensitive** between the name given and the name found, if you want to ignore the case you can use:

```python
results = HowLongToBeat(0.0).search("Awesome Game", similarity_case_sensitive=False)
```

**Remember** that, when searching by ID, the similarity value and the case-sensitive bool are **ignored**.

### Reading an entry

An entry is made of few values, you can check them [in the Entry class file](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py). It also include the full JSON of values (already converted to Python dict) received from HLTB.

## Issues, Questions & Discussions

If you found a bug report it as soon as you can creating an [issue](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/issues/new), the code may not be perfect.

If you need any new feature, or want to discuss the current implementation/features, consider opening a [discussion](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/discussions) or even propose a change with a [Pull Request](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/pulls).

## Authors

* **ScrappyCocco** - Thank you for using my API

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI",
    "name": "howlongtobeatpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "howlongtobeat gaming steam uplay origin time length how long to beat",
    "author": "ScrappyCocco",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/9a/1c/305cdc05610c2fae3f0acecb2997611a469b56c1ada888f597a71b6a1dff/howlongtobeatpy-1.0.14.tar.gz",
    "platform": null,
    "description": "# HowLongToBeat Python API\n\n[![Python Test Released Published Version](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/python-test-release.yml/badge.svg)](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/python-test-release.yml)\n[![CodeQL](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/actions/workflows/codeql-analysis.yml)\n\n[![codecov](https://codecov.io/gh/ScrappyCocco/HowLongToBeat-PythonAPI/branch/master/graph/badge.svg)](https://codecov.io/gh/ScrappyCocco/HowLongToBeat-PythonAPI)\n[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=ScrappyCocco_HowLongToBeat-PythonAPI&metric=bugs)](https://sonarcloud.io/dashboard?id=ScrappyCocco_HowLongToBeat-PythonAPI)\n\nA simple Python API to read data from howlongtobeat.com.\n\nIt is inspired by [ckatzorke - howlongtobeat](https://github.com/ckatzorke/howlongtobeat) JS API.\n\n## Content\n\n- [Usage](#usage)\n- [Installation](#installation)\n  - [Installing the package downloading the last release](#installing-the-package-downloading-the-last-release)\n  - [Installing the package from the source code](#installing-the-package-from-the-source-code)\n- [Usage in code](#usage-in-code)\n  - [Start including it in your file](#start-including-it-in-your-file)\n  - [Now call search()](#now-call-search)\n  - [Alternative search (by ID)](#alternative-search-by-id)\n  - [DLC search](#dlc-search)\n  - [Results auto-filter](#results-auto-filter)\n  - [Reading an entry](#reading-an-entry)\n- [Issues, Questions & Discussions](#issues-questions--discussions)\n- [Authors](#authors)\n- [License](#license)\n\n## Usage\n\n## Installation\n\n### Installing the package downloading the last release\n\n```python\npip install howlongtobeatpy\n```\n\n### Installing the package from the source code\n\nDownload the repo, enter the folder with 'setup.py' and run the command\n\n```python\npip install .\n```\n\n## Usage in code\n\n### Start including it in your file\n\n```python\nfrom howlongtobeatpy import HowLongToBeat\n```\n\n### Now call search()\n\nThe API main functions are:\n\n```python\nresults = HowLongToBeat().search(\"Awesome Game\")\n```\n\nor, if you prefer using async:\n\n```python\nresults = await HowLongToBeat().async_search(\"Awesome Game\")\n```\n\nThe return of that function is a **list** of possible games, or **None** in case you passed an invalid \"game name\" as parameter or if there was an error in the request.\n\nIf the list **is not None** you should choose the best entry checking the Similarity value with the original name, example:\n\n```python\nresults_list = await HowLongToBeat().async_search(\"Awesome Game\")\nif results_list is not None and len(results_list) > 0:\n    best_element = max(results_list, key=lambda element: element.similarity)\n```\n\nOnce done, \"best_element\" will contain the best game found in the research.\nEvery entry in the list (if not None in case of errors) is an object of type: [HowLongToBeatEntry](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py).\n\n### Alternative search (by ID)\n\nIf you prefer, you can get a game by ID, this can be useful if you already have the game's howlongtobeat-id (the ID is the number in the URL, for example in [https://howlongtobeat.com/game/7231]([hello](https://howlongtobeat.com/game/7231)) the ID is 7231).\n\nTo avoid a new parser, the search by ID use a first request to get the game title, and then use the standard search with that title, filtering the results and returning the unique game with that ID.\n\nRemember that it could be a bit slower, but you avoid searching the game in the array by similarity.\n\nHere's the example:\n\n```python\nresult = HowLongToBeat().search_from_id(123456)\n```\n\nor, if you prefer using async:\n\n```python\nresult = await HowLongToBeat().async_search_from_id(123456)\n```\n\nThis call will return an unique [HowLongToBeatEntry](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py) or None in case of errors.\n\n### DLC search\n\nAn `enum` has been added to have a filter in the search:\n\n```python\nSearchModifiers.NONE # default\nSearchModifiers.ISOLATE_DLC\nSearchModifiers.HIDE_DLC\n```\n\nThis optional parameter allow you to specify in the search if you want the default search (with DLCs), to HIDE DLCs and only show games, or to ISOLATE DLCs (show only DLCs).\n\n### Results auto-filter\n\nTo ignore games with a very different name, the standard search automatically filter results with a game name that has a similarity with the given name > than `0.4`, not adding the others to the result list.\nIf you want all the results, or you want to change this value, you can put a parameter in the constructor:\n\n```python\nresults = HowLongToBeat(0.0).search(\"Awesome Game\")\n```\n\nputting `0.0` (or just `0`) will return all the found games, otherwise you can write another (`float`) number between 0...1 to set a new filter, such as `0.7`.\n\nAlso remember that by default the similarity check **is case-sensitive** between the name given and the name found, if you want to ignore the case you can use:\n\n```python\nresults = HowLongToBeat(0.0).search(\"Awesome Game\", similarity_case_sensitive=False)\n```\n\n**Remember** that, when searching by ID, the similarity value and the case-sensitive bool are **ignored**.\n\n### Reading an entry\n\nAn entry is made of few values, you can check them [in the Entry class file](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py). It also include the full JSON of values (already converted to Python dict) received from HLTB.\n\n## Issues, Questions & Discussions\n\nIf you found a bug report it as soon as you can creating an [issue](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/issues/new), the code may not be perfect.\n\nIf you need any new feature, or want to discuss the current implementation/features, consider opening a [discussion](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/discussions) or even propose a change with a [Pull Request](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/pulls).\n\n## Authors\n\n* **ScrappyCocco** - Thank you for using my API\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python API for How Long to Beat",
    "version": "1.0.14",
    "project_urls": {
        "Homepage": "https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI"
    },
    "split_keywords": [
        "howlongtobeat",
        "gaming",
        "steam",
        "uplay",
        "origin",
        "time",
        "length",
        "how",
        "long",
        "to",
        "beat"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5d8d85dbb9cd1382bdb1d15a960982c42391b602fea680bc9c4ffc5b1d41f88b",
                "md5": "c50c432068ab7f0d543d004b87d7d9a1",
                "sha256": "e10a14d1414645d06078ebe9d7275206b703e241fa9390354804566923a0af33"
            },
            "downloads": -1,
            "filename": "howlongtobeatpy-1.0.14-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c50c432068ab7f0d543d004b87d7d9a1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11986,
            "upload_time": "2024-12-10T14:20:59",
            "upload_time_iso_8601": "2024-12-10T14:20:59.143134Z",
            "url": "https://files.pythonhosted.org/packages/5d/8d/85dbb9cd1382bdb1d15a960982c42391b602fea680bc9c4ffc5b1d41f88b/howlongtobeatpy-1.0.14-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a1c305cdc05610c2fae3f0acecb2997611a469b56c1ada888f597a71b6a1dff",
                "md5": "fc191db642d6cca305e53d35189be6fd",
                "sha256": "b49ab9f16af250a4bfd7a3dbc1266223f66776522770e4cb5c66e544ca5d6ef5"
            },
            "downloads": -1,
            "filename": "howlongtobeatpy-1.0.14.tar.gz",
            "has_sig": false,
            "md5_digest": "fc191db642d6cca305e53d35189be6fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14341,
            "upload_time": "2024-12-10T14:21:00",
            "upload_time_iso_8601": "2024-12-10T14:21:00.653733Z",
            "url": "https://files.pythonhosted.org/packages/9a/1c/305cdc05610c2fae3f0acecb2997611a469b56c1ada888f597a71b6a1dff/howlongtobeatpy-1.0.14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-10 14:21:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ScrappyCocco",
    "github_project": "HowLongToBeat-PythonAPI",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "howlongtobeatpy"
}
        
Elapsed time: 0.62491s