Package: howlongtobeatpy
HowLongToBeat Python APIA simple Python API to read data from howlongtobeat.com.It is inspired byckatzorke - howlongtobeatJS API.ContentUsageInstallationInstalling the package downloading the last releaseInstalling the package from the source codeUsage in codeStart including it in your fileNow call search()Alternative search (by ID)DLC searchResults auto-filterReading an entryIssues, Questions & DiscussionsAuthorsLicenseUsageInstallationInstalling the package downloading the last releasepipinstallhowlongtobeatpyInstalling the package from the source codeDownload the repo, enter the folder with 'setup.py' and run the commandpipinstall.Usage in codeStart including it in your filefromhowlongtobeatpyimportHowLongToBeatNow call search()The API main functions are:results=HowLongToBeat().search("Awesome Game")or, if you prefer using async:results=awaitHowLongToBeat().async_search("Awesome Game")The return of that function is alistof possible games, orNonein case you passed an invalid "game name" as parameter or if there was an error in the request.If the listis not Noneyou should choose the best entry checking the Similarity value with the original name, example:results_list=awaitHowLongToBeat().async_search("Awesome Game")ifresults_listisnotNoneandlen(results_list)>0:best_element=max(results_list,key=lambdaelement: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.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 inhttps://howlongtobeat.com/game/7231the 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:result=HowLongToBeat().search_from_id(123456)or, if you prefer using async:result=awaitHowLongToBeat().async_search_from_id(123456)This call will return an uniqueHowLongToBeatEntryor None in case of errors.DLC searchAnenumhas been added to have a filter in the search:SearchModifiers.NONE# defaultSearchModifiers.ISOLATE_DLCSearchModifiers.HIDE_DLCThis 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-filterTo 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 > than0.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:results=HowLongToBeat(0.0).search("Awesome Game")putting0.0(or just0) will return all the found games, otherwise you can write another (float) number between 0...1 to set a new filter, such as0.7.Also remember that by default the similarity checkis case-sensitivebetween the name given and the name found, if you want to ignore the case you can use:results=HowLongToBeat(0.0).search("Awesome Game",similarity_case_sensitive=False)Rememberthat, when searching by ID, the similarity value and the case-sensitive bool areignored.Reading an entryAn entry is made of few values, you can check themin the Entry class file. It also include the full JSON of values (already converted to Python dict) received from HLTB.Issues, Questions & DiscussionsIf you found a bug report it as soon as you can creating anissue, the code may not be perfect.If you need any new feature, or want to discuss the current implementation/features, consider opening adiscussionor even propose a change with aPull Request.AuthorsScrappyCocco- Thank you for using my APILicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details