Skip to content

Commit

Permalink
Fixed all bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kile committed Apr 2, 2021
1 parent 797eb02 commit 6882d9c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "pypxl"
version = "0.1.2"
version = "0.1.6"
description = "An Asynchronos API wrapper for https://pxlapi.dev"
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion pypxl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
__author__ = "Kile"
__license__ = "MIT"
__copyright__ = "Copyright 2021 Kile"
__version__ = "0.1.2"
__version__ = "0.1.6"

from .client import Pxlapi
17 changes: 9 additions & 8 deletions pypxl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

class Pxlapi():

FLAGS = ["asexual", "aromantic", "bisexual", "pansexual", "gay", "lesbian", "trans", "nonbinary", "genderfluid", "genderqueer", "polysexual", "austria", "belgium", "botswana", "bulgaria", "ivory", "estonia", "france", "gabon", "gambia", "germany", "guinea", "hungary", "indonesia", "ireland", "italy", "luxembourg", "monaco", "nigeria", "poland", "russia", "romania", "sierraleone", "thailand", "ukraine", "yemen"]
FILTERS = ["dog", "dog2", "dog3", "pig", "flowers", "random"]
SAFE_SEARCH = ["off", "moderate", "strict"]

def __init__(self, token:str, session=aiohttp.ClientSession(), stop_on_error:bool=False):
self.token = token
self.session = session
self.stop_on_error = stop_on_error

self.flags = ["asexual", "aromantic", "bisexual", "pansexual", "gay", "lesbian", "trans", "nonbinary", "genderfluid", "genderqueer", "polysexual", "austria", "belgium", "botswana", "bulgaria", "ivory", "estonia", "france", "gabon", "gambia", "germany", "guinea", "hungary", "indonesia", "ireland", "italy", "luxembourg", "monaco", "nigeria", "poland", "russia", "romania", "sierraleone", "thailand", "ukraine", "yemen"]
self.filters = ["dog", "dog2", "dog3", "pig", "flowers", "random"]
self.safe_search = ["off", "moderate", "strict"]

async def get_img(self, enpoint:str, body:dict):
session = aiohttp.ClientSession()
headers = {
Expand Down Expand Up @@ -65,7 +66,7 @@ async def emojaic(self, images:list, groupSize:int=12, scale:bool=False):


async def flag(self, flag:str, images:str, opacity:int=128):
if not flag.lower() in FLAGS:
if not flag.lower() in self.flags:
if self.stop_on_error:
raise InvalidFlag(f'Flag {flag.lower()} not a valid flag')
else:
Expand Down Expand Up @@ -98,8 +99,8 @@ async def lego(self, images:list, scale:bool=False, groupSize:int=8):
return await self.get_img('lego', body)


async def snapchat(self, filter:str, images:list, filters:list=FILTERS):
if not filter.lower() in FILTERS:
async def snapchat(self, filter:str, images:list, filters:list=None):
if not filter.lower() in self.filters:
if self.stop_on_error:
raise InvalidFilter(f'Flag {filter.lower()} not a valid flag')
else:
Expand Down Expand Up @@ -143,7 +144,7 @@ async def image_search(self, query:str, safeSearch:str='strict', meta:bool=False
raise TooManyCharacters("Too many characters used for the image_search endpoint")
else:
return "Too many characters used for the image_search endpoint"
if not safeSearch.lower() in SAFE_SEARCH:
if not safeSearch.lower() in self.safe_search:
if self.stop_on_error:
raise InvalidSafety("Invalid safety level for the image_search endpoint")
else:
Expand Down Expand Up @@ -175,7 +176,7 @@ async def web_search(self, query:str, safeSearch:str='strict'):
raise TooManyCharacters("Too many characters used for the web_search endpoint")
else:
return "Too many characters used for the web_search endpoint"
if not safeSearch.lower() in SAFE_SEARCH:
if not safeSearch.lower() in self.safe_search:
if self.stop_on_error:
raise InvalidSafety("Invalid safety level for the web_search endpoint")
else:
Expand Down

0 comments on commit 6882d9c

Please sign in to comment.