Skip to content

Commit f43c542

Browse files
committed
📦 0.2.1
Look in release description 👀
1 parent 1d95d5c commit f43c542

File tree

5 files changed

+98
-51
lines changed

5 files changed

+98
-51
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/__pycache__
2+
**/build
3+
**/pypxl.egg-info
4+
**/dist
5+
**/docs
6+
**/.DS_Store
7+
**/test

examples/glitch_discord.markdown

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ This would be an example for a small bot command
44
from pypxl import PxlClient
55
import discord
66
from discord.ext import commands
7-
import io
87

98
bot = commands.Bot(command_prefix= commands.when_mentioned_or('pxl.'), description="Testing pxlapi wrapper", case_insensitive=True)
109

@@ -15,7 +14,7 @@ async def glitch(ctx, url:str):
1514
data = await pxl.glitch(images=[url])
1615

1716
if data.success:
18-
f = discord.File(io.BytesIO(data), filename=f"glitch.{r.file_type}")
17+
f = discord.File(data.convert_to_ioBytes(), filename=f"glitch.{data.file_type}")
1918
await ctx.send(file=f)
2019
else:
2120
await ctx.send(":x: " + data.error)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[tool.poetry]
33
name = "pypxl"
4-
version = "0.2.0"
4+
version = "0.2.1"
55
description = "An Asynchronos API wrapper for https://pxlapi.dev"
66
license = "MIT"
77
readme = "README.md"

pypxl/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
__author__ = "Kile"
1010
__license__ = "MIT"
1111
__copyright__ = "Copyright 2021 Kile"
12-
__version__ = "0.2.0"
12+
__version__ = "0.2.1"
1313

1414
from .client import PxlClient

pypxl/client.py

+88-47
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from .errors import PxlapiException, InvalidFlag, TooManyCharacters, InvalidSafety, InvalidEyes
44
from .pxl_object import PxlObject
55

6-
class PxlClient():
6+
from typing import List
7+
8+
class PxlClient:
79
"""
810
The class which allows you to make requests to pxlapi
911
@@ -14,17 +16,17 @@ class PxlClient():
1416
`session (aiohttp client session)`: The session to use for requests
1517
`stop_on_error (boolean)`: If the code should raise an error if something went wrong or return the error text instead
1618
"""
17-
def __init__(self, token:str, session=aiohttp.ClientSession(), stop_on_error:bool=False):
19+
def __init__(self, token:str, session=aiohttp.ClientSession(), stop_on_error:bool=False) -> PxlObject:
1820
self.token = token
1921
self.session = session
2022
self.stop_on_error = stop_on_error
2123

2224
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"]
23-
self.filters = ["dog", "dog2", "dog3", "pig", "flowers", "random"]
25+
self.filters = ["dog", "dog2", "dog3", "pig", "flowers", "clown", "random"]
2426
self.safe_search = ["off", "moderate", "strict"]
2527
self.valid_eyes = ["big", "black", "bloodshot", "blue", "default", "googly", "green", "horror", "illuminati", "money", "pink", "red", "small", "spinner", "spongebob", "white", "yellow", "random"]
2628

27-
async def get_img(self, enpoint:str, body:dict):
29+
async def _get_img(self, enpoint:str, body:dict) -> PxlObject:
2830
"""
2931
The function making the request which gets image bytes in return. Not meant to be used outside of this class
3032
@@ -55,7 +57,7 @@ async def get_img(self, enpoint:str, body:dict):
5557
raise PxlapiException(error)
5658
return PxlObject(success=False, error=error)
5759

58-
async def get_text(self, enpoint:str, body:dict):
60+
async def _get_text(self, enpoint:str, body:dict) -> PxlObject:
5961
"""
6062
The function making the request which gets text in return. Not meant to be used outside of this class
6163
@@ -86,7 +88,7 @@ async def get_text(self, enpoint:str, body:dict):
8688

8789
return PxlObject(error=error, success=False)
8890

89-
async def emojaic(self, images:list, groupSize:int=12, scale:bool=False):
91+
async def emojaic(self, images:List[str], groupSize:int=12, scale:bool=False) -> PxlObject:
9092
"""
9193
Turns the provided images into images assebled by emojis
9294
@@ -104,9 +106,9 @@ async def emojaic(self, images:list, groupSize:int=12, scale:bool=False):
104106
'scale': scale
105107
}
106108

107-
return await self.get_img('emojimosaic', body)
109+
return await self._get_img('emojimosaic', body)
108110

109-
async def flag(self, flag:str, images:str, opacity:int=128):
111+
async def flag(self, flag:str, images:List[str], opacity:int=128) -> PxlObject:
110112
"""
111113
Turns the provided images into images with the flag specified
112114
@@ -128,9 +130,9 @@ async def flag(self, flag:str, images:str, opacity:int=128):
128130
'images': images,
129131
'opacity': opacity,
130132
}
131-
return await self.get_img(f'flag/{flag.lower()}', body)
133+
return await self._get_img(f'flag/{flag.lower()}', body)
132134

133-
async def ganimal(self, images:list):
135+
async def ganimal(self, images:List[str]) -> PxlObject:
134136
"""
135137
Turns the provided images into images with animal faces
136138
@@ -143,9 +145,24 @@ async def ganimal(self, images:list):
143145
body = {
144146
'images': images
145147
}
146-
return await self.get_img('ganimal', body)
148+
return await self._get_img('ganimal', body)
149+
150+
async def ajit(self, images:List[str]) -> PxlObject:
151+
"""
152+
Overlays an image of Ajit Pai snacking on some popcorn
153+
154+
# Parameters:
155+
`images (list)`: The images to proccess
147156
148-
async def flash(self, images:list):
157+
# Returns:
158+
`PxlObject`
159+
"""
160+
body = {
161+
'images': images
162+
}
163+
return await self._get_img('ajit', body)
164+
165+
async def flash(self, images:List[str]) -> PxlObject:
149166
"""
150167
Turns the provided images into flash images
151168
@@ -158,9 +175,9 @@ async def flash(self, images:list):
158175
body = {
159176
'images': images
160177
}
161-
return await self.get_img('flash', body)
178+
return await self._get_img('flash', body)
162179

163-
async def glitch(self, images:list, delay:int=100, count:int=10, amount:int=5, iterations:int=10, gif:bool=None):
180+
async def glitch(self, images:List[str], delay:int=100, count:int=10, amount:int=5, iterations:int=10, gif:bool=None) -> PxlObject:
164181
"""
165182
Turns the provided images into images into glitch GIFs and/or images
166183
@@ -183,9 +200,9 @@ async def glitch(self, images:list, delay:int=100, count:int=10, amount:int=5, i
183200
'iterations': iterations,
184201
'gif': gif
185202
}
186-
return await self.get_img('glitch', body)
203+
return await self._get_img('glitch', body)
187204

188-
async def lego(self, images:list, scale:bool=False, groupSize:int=8):
205+
async def lego(self, images:List[str], scale:bool=False, groupSize:int=8) -> PxlObject:
189206
"""
190207
Turns the provided images into images into images made up of lego bricks
191208
@@ -202,9 +219,9 @@ async def lego(self, images:list, scale:bool=False, groupSize:int=8):
202219
'scale': scale,
203220
'groupSize': groupSize
204221
}
205-
return await self.get_img('lego', body)
222+
return await self._get_img('lego', body)
206223

207-
async def jpeg(self, images:list, quality:int=1):
224+
async def jpeg(self, images:List[str], quality:int=1) -> PxlObject:
208225
"""
209226
Turns the provided images into lower quality
210227
@@ -219,9 +236,9 @@ async def jpeg(self, images:list, quality:int=1):
219236
'images': images,
220237
'quality': quality
221238
}
222-
return await self.get_img('jpeg', body)
239+
return await self._get_img('jpeg', body)
223240

224-
async def snapchat(self, filter:str, images:list, filters:list=None):
241+
async def snapchat(self, filter:str, images:List[str], filters:list=None) -> PxlObject:
225242
"""
226243
Turns the provided images into images with the snap filter provided if a face is detected
227244
@@ -237,15 +254,15 @@ async def snapchat(self, filter:str, images:list, filters:list=None):
237254
if self.stop_on_error:
238255
raise InvalidFilter(f'Flag {filter.lower()} not a valid filter')
239256
else:
240-
return f'Flag {filter.lower()} not a valid filter'
257+
return PxlObject(success=False, error=f'Flag {filter.lower()} not a valid filter')
241258

242259
body = {
243260
'images': images,
244261
'filters': filters
245262
}
246-
return await self.get_img(f'snapchat/{filter}', body)
263+
return await self._get_img(f'snapchat/{filter}', body)
247264

248-
async def eyes(self, eyes:str, images:list, filters:list=None):
265+
async def eyes(self, eyes:str, images:List[str], filters:list=None) -> PxlObject:
249266
"""
250267
Turns the provided images into images with a filter applied to the eyes of faces detected
251268
@@ -259,17 +276,17 @@ async def eyes(self, eyes:str, images:list, filters:list=None):
259276
"""
260277
if not eyes.lower() in self.valid_eyes:
261278
if self.stop_on_error:
262-
raise InvalidEyes(f'Flag {eyes.lower()} not a valid eye type')
279+
raise InvalidEyes(f'Eye {eyes.lower()} not a valid eye type')
263280
else:
264-
return f'Flag {eyes.lower()} not a valid eye type'
281+
return PxlObject(success=False, error=f'Eye {eyes.lower()} not a valid eye type')
265282

266283
body = {
267284
'images': images,
268285
'filters': filters
269286
}
270-
return await self.get_img(f'eyes/{eyes}', body)
287+
return await self._get_img(f'eyes/{eyes}', body)
271288

272-
async def thonkify(self, text:str):
289+
async def thonkify(self, text:str) -> PxlObject:
273290
"""
274291
Turns the provided text into an image with that text made up of thonks
275292
@@ -282,9 +299,9 @@ async def thonkify(self, text:str):
282299
body = {
283300
'text': text
284301
}
285-
return await self.get_img('thonkify', body)
302+
return await self._get_img('thonkify', body)
286303

287-
async def sonic(self, text:str):
304+
async def sonic(self, text:str) -> PxlObject:
288305
"""
289306
Turns the provided text into an image with sonic saying the provided text
290307
@@ -298,14 +315,38 @@ async def sonic(self, text:str):
298315
if self.stop_on_error:
299316
raise TooManyCharacters("Too many characters used for the sonic endpoint")
300317
else:
301-
return "Too many characters used for the sonic endpoint"
318+
return PxlObject(success=False, error="Too many characters used for the sonic endpoint")
302319

303320
body = {
304321
'text': text
305322
}
306-
return await self.get_img('sonic', body)
323+
return await self._get_img('sonic', body)
324+
325+
async def klines(self, pair:str=None, interval:str="1m", limit:int=90, ticks:List[int]=None, custom:dict=None):
326+
"""
327+
Creates a candlestick chart for the given coin pair / ticks
328+
329+
# Parameters:
330+
`pair (string)`: The [coin pair](https://www.binance.com/api/v3/exchangeInfo) to generate a candlestick chart for (e.g. `BNBBUSD`). Optional if custom ticks are sent.
331+
`interval (string)`: Timespan between candlesticks
332+
`limit (int)`: How many candlesticks to draw
333+
`ticks (list)`: Custom ticks (lets you send in [binance API compatible](https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#klinecandlestick-data) tick data)
334+
`custom (dict)`: Custom pair data to display
335+
key `baseAsset (string)`: Custom base asset name to display
336+
value `quoteAsset (string)`: Custom quote asset name to display
337+
338+
# Returns:
339+
`PxlObject`
340+
"""
341+
body = {
342+
"interval": interval,
343+
"limit": limit,
344+
"ticks": ticks,
345+
"pair": pair,
346+
}
347+
return await self._get_img(f"klines{f'/{pair}' if pair else ''}", body)
307348

308-
async def imagescript(self, version:str, code:str, inject=None, timeout:int=10000):
349+
async def imagescript(self, version:str, code:str, inject=None, timeout:int=10000) -> PxlObject:
309350
"""
310351
Evaluates code
311352
@@ -323,9 +364,9 @@ async def imagescript(self, version:str, code:str, inject=None, timeout:int=1000
323364
'inject': inject,
324365
'timeout': timeout
325366
}
326-
return await self.get_img(f'imagescript/{version}', body)
367+
return await self._get_img(f'imagescript/{version}', body)
327368

328-
async def imagescript_version(self):
369+
async def imagescript_version(self) -> PxlObject:
329370
"""
330371
Gives you the available versions for imagescript
331372
@@ -336,9 +377,9 @@ async def imagescript_version(self):
336377
`PxlObject`
337378
"""
338379
body = {}
339-
return await self.get_text('imagescript/versions', body)
380+
return await self._get_text('imagescript/versions', body)
340381

341-
async def image_search(self, query:str, safeSearch:str='strict', meta:bool=False):
382+
async def image_search(self, query:str, safeSearch:str='strict', meta:bool=False) -> PxlObject:
342383
"""
343384
Looks for images with provided query
344385
@@ -354,26 +395,26 @@ async def image_search(self, query:str, safeSearch:str='strict', meta:bool=False
354395
if self.stop_on_error:
355396
raise TooManyCharacters("Too many characters used for the image_search endpoint")
356397
else:
357-
return "Too many characters used for the image_search endpoint"
398+
return PxlObject(success=False, error="Too many characters used for the image_search endpoint")
358399
if not safeSearch.lower() in self.safe_search:
359400
if self.stop_on_error:
360401
raise InvalidSafety("Invalid safety level for the image_search endpoint")
361402
else:
362-
return "Invalid safety level for the image_search endpoint"
403+
return PxlObject(success=False, error="Invalid safety level for the image_search endpoint")
363404

364405
body = {
365406
'query': query,
366407
'safeSearch': safeSearch,
367408
'meta': meta
368409
}
369-
return await self.get_text('image_search', body)
410+
return await self._get_text('image_search', body)
370411

371-
async def screenshot(self, url:str, device:str=None, locale:str='en_US', blocklist:list=[], defaultBlocklist:bool=True, browser:str='chromium', theme:str='dark', timeout:int=30000, fullPage:bool=False):
412+
async def screenshot(self, url:str, device:str=None, locale:str='en_US', blocklist:list=[], defaultBlocklist:bool=True, browser:str='chromium', theme:str='dark', timeout:int=30000, fullPage:bool=False) -> PxlObject:
372413
"""
373414
Screenshots the webpage provided
374415
375416
# Parameters:
376-
`url (string): The website to screenshot
417+
`url (string) -> PxlObject: The website to screenshot
377418
`device (string)`: The device to emulate. See [list of available devices](https://github.com/microsoft/playwright/blob/17e953c2d8bd19ace20059ffaaa85f3f23cfb19d/src/server/deviceDescriptors.js#L21-L857). Defaults to a non-specific browser with a viewport of 1920x1080 pixels.
378419
`locale (string)`: The locale to set the browser to
379420
`blocklist (list)`: A list of domains to block
@@ -396,14 +437,14 @@ async def screenshot(self, url:str, device:str=None, locale:str='en_US', blockli
396437
'theme': theme,
397438
'timeout': timeout
398439
}
399-
return await self.get_img('screenshot', body)
440+
return await self._get_img('screenshot', body)
400441

401-
async def web_search(self, query:str, safeSearch:str='strict'):
442+
async def web_search(self, query:str, safeSearch:str='strict') -> PxlObject:
402443
"""
403444
Searches for the querie provided
404445
405446
# Parameters:
406-
`url (string): The website to screenshot
447+
`url (string) -> PxlObject: The website to screenshot
407448
`safeSearch (string)`: What safe search setting to use
408449
409450
# Returns:
@@ -413,15 +454,15 @@ async def web_search(self, query:str, safeSearch:str='strict'):
413454
if self.stop_on_error:
414455
raise TooManyCharacters("Too many characters used for the web_search endpoint")
415456
else:
416-
return "Too many characters used for the web_search endpoint"
457+
return PxlObject(success=False, error="Too many characters used for the web_search endpoint")
417458
if not safeSearch.lower() in self.safe_search:
418459
if self.stop_on_error:
419460
raise InvalidSafety("Invalid safety level for the web_search endpoint")
420461
else:
421-
return "Invalid safety level for the web_search endpoint"
462+
return PxlObject(success=False, error="Invalid safety level for the web_search endpoint")
422463

423464
body = {
424465
'query': query,
425466
'safeSearch': safeSearch
426467
}
427-
return await self.get_text('web_search', body)
468+
return await self._get_text('web_search', body)

0 commit comments

Comments
 (0)