-
-
Notifications
You must be signed in to change notification settings - Fork 19
Home
ヘンタイちゃん edited this page Nov 22, 2020
·
14 revisions
Welcome to the hentai wiki! This is the right place if you need some help using this module. The examples you see here work with the most recent version of hentai. Note that sometimes even patches can introduce breaking changes in functions and properties where I see it necessary. As of version 3.1.3
, most code signatures shouldn't change much anymore. See also the change log to help you migrate updates. The documentation online always reflects the last stable release.
#!/usr/bin/env python3
from pathlib import Path
from hentai import Hentai, Utils, Option, Format
def main():
# create request to nhentai.net
homepage = Utils.get_homepage().popular_now
# print title and upload date
for index, doujin in enumerate(homepage):
print(f"{str(index+1).zfill(2)})\t{doujin.upload_date}\t{doujin.title(Format.Pretty)}")
# store selected data from response to disk
Utils.static(homepage, Path('homepage.json'), options=[Option.Title, Option.Epos])
if __name__ == '__main__':
main()
New in version 3.1.2
: the utils decorator; this type of method invocation is more secure and returns
a red-colored error message to the screen if error_msg
is enabled:
#!/usr/bin/env python3
from hentai import Hentai, Utils
@Utils.exists(error_msg=True)
def main():
doujin = Hentai(123456789)
print(doujin.title())
if __name__ == '__main__':
main()
print('done!')
# 404 Client Error: Not Found for url: https://nhentai.net/api/gallery/123456789
# done!
This is equivalent to calling
#!/usr/bin/env python3
from hentai import Hentai
from colorama import Fore, init
from requests import HTTPError
init(autoreset=True)
def main(error_msg: bool=False):
try:
doujin = Hentai(123456789)
except HTTPError as error:
if error_msg:
print(f"{Fore.RED}{error}")
else:
print(doujin.title())
if __name__ == '__main__':
main(error_msg=True)
print('done!')
# 404 Client Error: Not Found for url: https://nhentai.net/api/gallery/123456789
# done!