diff --git a/booru/client/atfbooru.py b/booru/client/atfbooru.py index c40ac29..a19491c 100644 --- a/booru/client/atfbooru.py +++ b/booru/client/atfbooru.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image_danbooru, get_hostname @@ -17,7 +16,7 @@ class Atfbooru(object): Search and gets images from atfbooru. search_image : function - Gets images, image urls only from atfbooru. + Search and gets images from atfbooru, but only returns image. """ @@ -50,7 +49,6 @@ def __init__(self, api_key: str = "", user_id: str = ""): ---------- api_key : str Your API Key which is accessible within your account options page - user_id : str Your user ID, which is accessible on the account options/profile page. """ @@ -72,7 +70,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -101,7 +99,7 @@ async def search( elif block and re.findall(block, query): raise ValueError(Booru.error_handling_sameval) - + self.query = query self.specs["tags"] = self.query self.specs["limit"] = limit @@ -109,7 +107,7 @@ async def search( raw_data = await request(site=Booru.atfbooru, params_x=self.specs, block=block) self.appended = Atfbooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) diff --git a/booru/client/behoimi.py b/booru/client/behoimi.py index 9cdd6c4..2437d71 100644 --- a/booru/client/behoimi.py +++ b/booru/client/behoimi.py @@ -1,9 +1,8 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname -from random import shuffle, randint +from random import shuffle Booru = Api() @@ -11,7 +10,7 @@ class Behoimi(object): - """3d booru / Behoimi wrapper + """3d booru / Behoimi Client Methods ------- @@ -19,16 +18,10 @@ class Behoimi(object): Search and gets images from behoimi. search_image : function - Gets images, image urls only from behoimi. + Search and gets images from behoimi, but only returns image. """ - @staticmethod - async def mock(site: str, params: dict): - async with aiohttp.ClientSession(headers=Booru.behoimi_bypass) as session: - async with session.get(site, params=params) as resp: - return await resp.json() - @staticmethod def append_object(raw_object: dict): """Extends new object to the raw dict @@ -62,7 +55,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search and gets images from behoimi. @@ -70,19 +63,14 @@ async def search( ---------- query : str The query to search for. - block : str The tags to block. - limit : int The limit of images to return. - page : int The number of desired page - random : bool Shuffle the whole dict, default is True. - gacha : bool Get random single object, limit property will be ignored. @@ -104,7 +92,7 @@ async def search( raw_data = await request(site=Booru.behoimi, params_x=self.specs, block=block) self.appended = Behoimi.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -118,7 +106,7 @@ async def search( async def search_image( self, query: str, block="", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Gets images, meant just image urls from behoimi. @@ -126,13 +114,10 @@ async def search_image( ---------- query : str The query to search for. - block : str The tags to block. - limit : int The limit of images to return. - page : int The number of desired page diff --git a/booru/client/danbooru.py b/booru/client/danbooru.py index 08a11bd..8a0542b 100644 --- a/booru/client/danbooru.py +++ b/booru/client/danbooru.py @@ -1,9 +1,8 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image_danbooru, get_hostname -from random import shuffle, randint +from random import shuffle Booru = Api() @@ -17,7 +16,7 @@ class Danbooru(object): Search and gets images from danbooru. search_image : function - Gets images, image urls only from danbooru. + Search and gets images from danbooru, but only returns image. """ @@ -55,7 +54,7 @@ def __init__(self, api_key: str = "", login: str = ""): Your user ID, which is accessible on the account options/profile page. """ - if api_key =="" and login == "": + if api_key == "" and login == "": self.api_key = None self.login = None self.specs = {} @@ -64,8 +63,6 @@ def __init__(self, api_key: str = "", login: str = ""): self.login = login self.specs = {"api_key": self.api_key, "login": self.login} - - async def search( self, query: str, @@ -74,7 +71,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -103,7 +100,7 @@ async def search( elif block and re.findall(block, query): raise ValueError(Booru.error_handling_sameval) - + self.query = query self.specs["tags"] = self.query self.specs["limit"] = limit @@ -111,7 +108,7 @@ async def search( raw_data = await request(site=Booru.danbooru, params_x=self.specs, block=block) self.appended = Danbooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -144,7 +141,6 @@ async def search_image( ------- dict The json object (as string, you may need booru.resolve()) - """ if limit > 1000: diff --git a/booru/client/derpibooru.py b/booru/client/derpibooru.py index 93e5de1..96e266b 100644 --- a/booru/client/derpibooru.py +++ b/booru/client/derpibooru.py @@ -2,7 +2,7 @@ from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname -from random import shuffle, randint +from random import shuffle Booru = Api() @@ -16,7 +16,7 @@ class Derpibooru(object): Search and gets images from derpibooru. search_image : function - Gets images, image urls only from derpibooru. + Search and gets images from derpibooru, but only returns image. """ @@ -102,7 +102,7 @@ async def search( raw_data = await request(site=Booru.derpibooru, params_x=self.specs, block="") self.appended = Derpibooru.append_object(raw_data["images"]) - + try: if gacha: return better_object(roll(self.appended)) @@ -114,7 +114,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image(self, query: str, limit: int = 100, page: int = 1) -> Union[aiohttp.ClientResponse, str]: + async def search_image( + self, query: str, limit: int = 100, page: int = 1 + ) -> Union[aiohttp.ClientResponse, str]: """Gets images, meant just image urls from derpibooru. diff --git a/booru/client/e621.py b/booru/client/e621.py index d666933..f003338 100644 --- a/booru/client/e621.py +++ b/booru/client/e621.py @@ -106,7 +106,7 @@ async def search( raw_data = await request(site=Booru.e621, params_x=self.specs, block="") self.appended = E621.append_object(raw_data["posts"]) - + try: if gacha: return better_object(roll(self.appended)) diff --git a/booru/client/e926.py b/booru/client/e926.py index 3e4cfb4..3cd0066 100644 --- a/booru/client/e926.py +++ b/booru/client/e926.py @@ -106,7 +106,7 @@ async def search( raw_data = await request(site=Booru.e926, params_x=self.specs, block="") self.appended = E926.append_object(raw_data["posts"]) - + try: if gacha: return better_object(roll(self.appended)) @@ -145,7 +145,6 @@ async def search_image( if limit > 1000: raise ValueError(Booru.error_handling_limit) - self.query = query self.specs["tags"] = self.query self.specs["limit"] = limit diff --git a/booru/client/furbooru.py b/booru/client/furbooru.py index 7fa072b..3012cf8 100644 --- a/booru/client/furbooru.py +++ b/booru/client/furbooru.py @@ -113,11 +113,15 @@ async def search( try: if gacha: - return better_object(self.not_random[randint(0, len(self.not_random))]) + return better_object( + self.not_random[randint(0, len(self.not_random))] + ) elif random: return better_object(self.not_random) else: - return better_object(Furbooru.append_object(self.final["images"])) + return better_object( + Furbooru.append_object(self.final["images"]) + ) except Exception as e: raise Exception(f"Failed to get data: {e}") @@ -147,7 +151,6 @@ async def search_image(self, query: str, limit: int = 100, page: int = 1): if limit > 1000: raise ValueError(Booru.error_handling_limit) - self.query = query self.specs["q"] = self.query self.specs["per_page"] = limit diff --git a/booru/client/gelbooru.py b/booru/client/gelbooru.py index d30fd36..5e1ad1e 100644 --- a/booru/client/gelbooru.py +++ b/booru/client/gelbooru.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname @@ -17,7 +16,7 @@ class Gelbooru(object): Search and gets images from gelbooru. search_image : function - Gets images, meant just image urls from gelbooru. + Search and gets images from gelbooru, but only returns image. """ @@ -49,10 +48,10 @@ def __init__(self, api_key: str = "", user_id: str = ""): Parameters ---------- api_key : str - Your API Key which is accessible within your account options page + Your API Key (If possible) user_id : str - Your user ID, which is accessible on the account options/profile page. + Your user ID (If possible) """ if api_key and user_id == "": @@ -72,7 +71,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -111,7 +110,7 @@ async def search( raw_data = await request(site=Booru.gelbooru, params_x=self.specs, block=block) self.appended = Gelbooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -122,10 +121,10 @@ async def search( return better_object(Gelbooru.append_object(self.appended)) except Exception as e: raise Exception(f"Failed to get data: {e}") - + async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Parses image only @@ -149,7 +148,6 @@ async def search_image( if limit > 1000: raise ValueError(Booru.error_handling_limit) - elif block and re.findall(block, query): raise ValueError(Booru.error_handling_sameval) diff --git a/booru/client/hypnohub.py b/booru/client/hypnohub.py index 1ce6ca0..acca204 100644 --- a/booru/client/hypnohub.py +++ b/booru/client/hypnohub.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname @@ -17,7 +16,7 @@ class Hypnohub(object): Search and gets images from hypnohub. search_image : function - Gets images, image urls only from hypnohub. + Search and gets images from hypnohub, but only returns image. """ @@ -44,15 +43,15 @@ def append_object(raw_object: dict): return raw_object def __init__(self, api_key: str = "", user_id: str = ""): - """Initializes danbooru. + """Initializes hypnohub. Parameters ---------- api_key : str - Your API Key which is accessible within your account options page + Your API Key (If possible) user_id : str - Your user ID, which is accessible on the account options/profile page. + Your user ID (If possible) """ if api_key and user_id == "": @@ -72,7 +71,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -110,7 +109,7 @@ async def search( raw_data = await request(site=Booru.hypnohub, params_x=self.specs, block=block) self.appended = Hypnohub.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -122,10 +121,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str, None]: + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/konachan.py b/booru/client/konachan.py index c0993a0..0f48dc6 100644 --- a/booru/client/konachan.py +++ b/booru/client/konachan.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname @@ -17,7 +16,7 @@ class Konachan(object): Search and gets images from konachan. search_image : function - Gets images, image urls only from konachan. + Search and gets images from konachan, but only returns image. """ @@ -54,7 +53,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -91,7 +90,7 @@ async def search( raw_data = await request(site=Booru.konachan, params_x=self.specs, block=block) self.appended = Konachan.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -102,8 +101,10 @@ async def search( return better_object(Konachan.append_object(self.appended)) except Exception as e: raise Exception(f"Failed to get data: {e}") - - async def search_image(self, query: str, block: str = "", limit: int = 100, page: int = 1): + + async def search_image( + self, query: str, block: str = "", limit: int = 100, page: int = 1 + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/konachan_net.py b/booru/client/konachan_net.py index a4f4640..06d65ff 100644 --- a/booru/client/konachan_net.py +++ b/booru/client/konachan_net.py @@ -1,9 +1,8 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname -from random import shuffle, randint +from random import shuffle Booru = Api() @@ -17,7 +16,7 @@ class Konachan_Net(object): Search and gets images from konachan net. search_image : function - Gets images, image urls only from konachan net. + Search and gets images from konachan net, but only returns image. """ @@ -54,7 +53,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -89,9 +88,11 @@ async def search( self.specs["limit"] = limit self.specs["page"] = page - raw_data = await request(site=Booru.konachan_net, params_x=self.specs, block=block) + raw_data = await request( + site=Booru.konachan_net, params_x=self.specs, block=block + ) self.appended = Konachan_Net.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -102,8 +103,10 @@ async def search( return better_object(Konachan_Net.append_object(self.appended)) except Exception as e: raise Exception(f"Failed to get data: {e}") - - async def search_image(self, query: str, block: str = "", limit: int = 100, page: int = 1): + + async def search_image( + self, query: str, block: str = "", limit: int = 100, page: int = 1 + ) -> Union[list, str, None]: """Parses image only @@ -135,7 +138,9 @@ async def search_image(self, query: str, block: str = "", limit: int = 100, page self.specs["limit"] = limit self.specs["page"] = page - raw_data = await request(site=Booru.konachan_net, params_x=self.specs, block=block) + raw_data = await request( + site=Booru.konachan_net, params_x=self.specs, block=block + ) self.appended = Konachan_Net.append_object(raw_data) try: diff --git a/booru/client/lolibooru.py b/booru/client/lolibooru.py index 04ef9c8..bc46efb 100644 --- a/booru/client/lolibooru.py +++ b/booru/client/lolibooru.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname @@ -18,7 +17,7 @@ class Lolibooru(object): Search and gets images from lolibooru. search_image : function - Gets images, image urls only from lolibooru. + Search and gets images from lolibooru, but only returns image. """ @@ -55,7 +54,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -92,7 +91,7 @@ async def search( raw_data = await request(site=Booru.lolibooru, params_x=self.specs, block=block) self.appended = Lolibooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -103,8 +102,10 @@ async def search( return better_object(Lolibooru.append_object(self.appended)) except Exception as e: raise Exception(f"Failed to get data: {e}") - - async def search_image(self, query: str, block: str = "", limit: int = 100, page: int = 1): + + async def search_image( + self, query: str, block: str = "", limit: int = 100, page: int = 1 + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/paheal.py b/booru/client/paheal.py index 5b22ee5..4dffd33 100644 --- a/booru/client/paheal.py +++ b/booru/client/paheal.py @@ -18,7 +18,7 @@ class Paheal(object): Search and gets images from paheal. search_image : function - Gets images, meant just image urls from paheal. + Search and gets images from paheal, but only returns image. """ @@ -79,13 +79,11 @@ async def search( if limit > 1000: raise ValueError(Booru.error_handling_limit) - self.tags = query self.specs["tags"] = self.tags self.specs["limit"] = limit self.specs["page"] = page - async with aiohttp.ClientSession() as session: async with session.get(Booru.paheal, params=self.specs) as resp: self.data = await resp.text() @@ -111,10 +109,12 @@ async def search( else: return better_object(self.not_random) - except: - raise ValueError(f"Failed to get data") + except Exception as e: + raise Exception(f"Failed to get data: {e}") - async def search_image(self, query: str, limit: int = 100, page: int = 1) -> Union[aiohttp.ClientResponse, str]: + async def search_image( + self, query: str, limit: int = 100, page: int = 1 + ) -> Union[aiohttp.ClientResponse, str]: """Gets images, meant just image urls from paheal. @@ -139,7 +139,6 @@ async def search_image(self, query: str, limit: int = 100, page: int = 1) -> Uni if limit > 1000: raise ValueError(Booru.error_handling_limit) - self.tags = query self.specs["tags"] = self.tags self.specs["limit"] = limit diff --git a/booru/client/realbooru.py b/booru/client/realbooru.py index 91310d0..a6ba1a0 100644 --- a/booru/client/realbooru.py +++ b/booru/client/realbooru.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from random import shuffle from ..utils.fetch import request, roll @@ -17,7 +16,7 @@ class Realbooru(object): Search and gets images from realbooru. search_image : function - Gets images, image urls only from realbooru. + Search and gets images from realbooru, but only returns image. """ @@ -44,7 +43,6 @@ def append_object(raw_object: dict): "post_url" ] = f"{get_hostname(Booru.realbooru)}/index.php?page=post&s=view&id={raw_object[i]['id']}" - elif not raw_object[i]["directory"]: raw_object[i][ "file_url" @@ -52,7 +50,7 @@ def append_object(raw_object: dict): raw_object[i][ "post_url" ] = f"{get_hostname(Booru.realbooru)}/index.php?page=post&s=view&id={raw_object[i]['id']}" - + raw_object[i][ "directory" ] = f"{raw_object[i]['image'][0:2]}/{raw_object[i]['image'][2:4]}" @@ -71,10 +69,10 @@ def __init__(self, api_key: str = "", user_id: str = ""): Parameters ---------- api_key : str - Your API Key which is accessible within your account options page + Your API Key (If possible) user_id : str - Your user ID, which is accessible on the account options/profile page. + Your user ID (If possible) """ if api_key and user_id == "": @@ -94,7 +92,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -132,7 +130,7 @@ async def search( raw_data = await request(site=Booru.realbooru, params_x=self.specs, block=block) self.appended = Realbooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -144,10 +142,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str, None]: + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/rule34.py b/booru/client/rule34.py index dd536b1..c08e365 100644 --- a/booru/client/rule34.py +++ b/booru/client/rule34.py @@ -1,9 +1,8 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname -from random import shuffle, randint +from random import shuffle Booru = Api() @@ -14,10 +13,10 @@ class Rule34(object): Methods ------- search : function - Search and gets images from rule34. + Search method for rule34. search_image : function - Parses the image url only. + Search method for rule34, but only returns image. """ @@ -55,7 +54,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -93,7 +92,7 @@ async def search( raw_data = await request(site=Booru.rule34, params_x=self.specs, block=block) self.appended = Rule34.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -105,10 +104,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str, None]: + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/safebooru.py b/booru/client/safebooru.py index daac8e5..581eb4c 100644 --- a/booru/client/safebooru.py +++ b/booru/client/safebooru.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from random import shuffle from ..utils.fetch import request, roll @@ -14,10 +13,10 @@ class Safebooru(object): Methods ------- search : function - Search and gets images from safebooru. + Search method for safebooru. search_image : function - Gets images, image urls only from safebooru. + Search method for safebooru, but only returns image. """ @@ -52,10 +51,10 @@ def __init__(self, api_key: str = "", user_id: str = ""): Parameters ---------- api_key : str - Your API Key which is accessible within your account options page + Your API Key (If possible) user_id : str - Your user ID, which is accessible on the account options/profile page. + Your user ID (If possible) """ if api_key and user_id == "": @@ -75,7 +74,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -113,7 +112,7 @@ async def search( raw_data = await request(site=Booru.safebooru, params_x=self.specs, block=block) self.appended = Safebooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -125,10 +124,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str, None]: + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/tbib.py b/booru/client/tbib.py index 05a8360..9b8f8dd 100644 --- a/booru/client/tbib.py +++ b/booru/client/tbib.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from random import shuffle from ..utils.fetch import request, roll @@ -14,10 +13,10 @@ class Tbib(object): Methods ------- search : function - Search and gets images from tbib. + Search method for tbib. search_image : function - Gets images, image urls only from tbib. + Search method for tbib, but only returns image. """ @@ -52,10 +51,10 @@ def __init__(self, api_key: str = "", user_id: str = ""): Parameters ---------- api_key : str - Your API Key which is accessible within your account options page + Your API Key (If possible) user_id : str - Your user ID, which is accessible on the account options/profile page. + Your user ID (If possible) """ if api_key and user_id == "": @@ -75,7 +74,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -113,7 +112,7 @@ async def search( raw_data = await request(site=Booru.tbib, params_x=self.specs, block=block) self.appended = Tbib.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -125,10 +124,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str, None]: + ) -> Union[list, str, None]: """Parses image only @@ -149,7 +147,6 @@ async def search_image( The json object (as string, you may need booru.resolve()) """ - if limit > 1000: raise ValueError(Booru.error_handling_limit) if block and re.findall(block, query): diff --git a/booru/client/xbooru.py b/booru/client/xbooru.py index 7696374..58f702a 100644 --- a/booru/client/xbooru.py +++ b/booru/client/xbooru.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from random import shuffle from ..utils.fetch import request, roll @@ -14,10 +13,10 @@ class Xbooru(object): Methods ------- search : function - Search and gets images from xbooru. + Search method for xbooru. search_image : function - Gets images, image urls only from xbooru. + Search method for xbooru, but only returns image. """ @@ -52,10 +51,10 @@ def __init__(self, api_key: str = "", user_id: str = ""): Parameters ---------- api_key : str - Your API Key which is accessible within your account options page + Your API Key (If possible) user_id : str - Your user ID, which is accessible on the account options/profile page. + Your user ID (If possible) """ if api_key and user_id == "": @@ -75,7 +74,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -113,7 +112,7 @@ async def search( raw_data = await request(site=Booru.xbooru, params_x=self.specs, block=block) self.appended = Xbooru.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -125,10 +124,9 @@ async def search( except Exception as e: raise Exception(f"Failed to get data: {e}") - async def search_image( self, query: str, block: str = "", limit: int = 100, page: int = 1 - ) -> Union[aiohttp.ClientResponse, str, None]: + ) -> Union[list, str, None]: """Parses image only diff --git a/booru/client/yandere.py b/booru/client/yandere.py index 066d21a..3858bfa 100644 --- a/booru/client/yandere.py +++ b/booru/client/yandere.py @@ -1,5 +1,4 @@ import re -import aiohttp from typing import Union from ..utils.fetch import request, roll from ..utils.constant import Api, better_object, parse_image, get_hostname @@ -14,10 +13,10 @@ class Yandere(object): Methods ------- search : function - Search and gets images from yandere. + Search method for yandere. search_image : function - Gets images, image urls only from yandere. + Search method for yandere, but only returns image. """ @@ -54,7 +53,7 @@ async def search( page: int = 1, random: bool = True, gacha: bool = False, - ) -> Union[aiohttp.ClientResponse, str]: + ) -> Union[list, str, None]: """Search method @@ -91,7 +90,7 @@ async def search( raw_data = await request(site=Booru.yandere, params_x=self.specs, block=block) self.appended = Yandere.append_object(raw_data) - + try: if gacha: return better_object(roll(self.appended)) @@ -102,8 +101,10 @@ async def search( return better_object(Yandere.append_object(self.appended)) except Exception as e: raise Exception(f"Failed to get data: {e}") - - async def search_image(self, query: str, block: str = "", limit: int = 100, page: int = 1): + + async def search_image( + self, query: str, block: str = "", limit: int = 100, page: int = 1 + ) -> Union[list, str, None]: """Parses image only