3
3
from .errors import PxlapiException , InvalidFlag , TooManyCharacters , InvalidSafety , InvalidEyes
4
4
from .pxl_object import PxlObject
5
5
6
- class PxlClient ():
6
+ from typing import List
7
+
8
+ class PxlClient :
7
9
"""
8
10
The class which allows you to make requests to pxlapi
9
11
@@ -14,17 +16,17 @@ class PxlClient():
14
16
`session (aiohttp client session)`: The session to use for requests
15
17
`stop_on_error (boolean)`: If the code should raise an error if something went wrong or return the error text instead
16
18
"""
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 :
18
20
self .token = token
19
21
self .session = session
20
22
self .stop_on_error = stop_on_error
21
23
22
24
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" ]
24
26
self .safe_search = ["off" , "moderate" , "strict" ]
25
27
self .valid_eyes = ["big" , "black" , "bloodshot" , "blue" , "default" , "googly" , "green" , "horror" , "illuminati" , "money" , "pink" , "red" , "small" , "spinner" , "spongebob" , "white" , "yellow" , "random" ]
26
28
27
- async def get_img (self , enpoint :str , body :dict ):
29
+ async def _get_img (self , enpoint :str , body :dict ) -> PxlObject :
28
30
"""
29
31
The function making the request which gets image bytes in return. Not meant to be used outside of this class
30
32
@@ -55,7 +57,7 @@ async def get_img(self, enpoint:str, body:dict):
55
57
raise PxlapiException (error )
56
58
return PxlObject (success = False , error = error )
57
59
58
- async def get_text (self , enpoint :str , body :dict ):
60
+ async def _get_text (self , enpoint :str , body :dict ) -> PxlObject :
59
61
"""
60
62
The function making the request which gets text in return. Not meant to be used outside of this class
61
63
@@ -86,7 +88,7 @@ async def get_text(self, enpoint:str, body:dict):
86
88
87
89
return PxlObject (error = error , success = False )
88
90
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 :
90
92
"""
91
93
Turns the provided images into images assebled by emojis
92
94
@@ -104,9 +106,9 @@ async def emojaic(self, images:list, groupSize:int=12, scale:bool=False):
104
106
'scale' : scale
105
107
}
106
108
107
- return await self .get_img ('emojimosaic' , body )
109
+ return await self ._get_img ('emojimosaic' , body )
108
110
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 :
110
112
"""
111
113
Turns the provided images into images with the flag specified
112
114
@@ -128,9 +130,9 @@ async def flag(self, flag:str, images:str, opacity:int=128):
128
130
'images' : images ,
129
131
'opacity' : opacity ,
130
132
}
131
- return await self .get_img (f'flag/{ flag .lower ()} ' , body )
133
+ return await self ._get_img (f'flag/{ flag .lower ()} ' , body )
132
134
133
- async def ganimal (self , images :list ) :
135
+ async def ganimal (self , images :List [ str ]) -> PxlObject :
134
136
"""
135
137
Turns the provided images into images with animal faces
136
138
@@ -143,9 +145,24 @@ async def ganimal(self, images:list):
143
145
body = {
144
146
'images' : images
145
147
}
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
147
156
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 :
149
166
"""
150
167
Turns the provided images into flash images
151
168
@@ -158,9 +175,9 @@ async def flash(self, images:list):
158
175
body = {
159
176
'images' : images
160
177
}
161
- return await self .get_img ('flash' , body )
178
+ return await self ._get_img ('flash' , body )
162
179
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 :
164
181
"""
165
182
Turns the provided images into images into glitch GIFs and/or images
166
183
@@ -183,9 +200,9 @@ async def glitch(self, images:list, delay:int=100, count:int=10, amount:int=5, i
183
200
'iterations' : iterations ,
184
201
'gif' : gif
185
202
}
186
- return await self .get_img ('glitch' , body )
203
+ return await self ._get_img ('glitch' , body )
187
204
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 :
189
206
"""
190
207
Turns the provided images into images into images made up of lego bricks
191
208
@@ -202,9 +219,9 @@ async def lego(self, images:list, scale:bool=False, groupSize:int=8):
202
219
'scale' : scale ,
203
220
'groupSize' : groupSize
204
221
}
205
- return await self .get_img ('lego' , body )
222
+ return await self ._get_img ('lego' , body )
206
223
207
- async def jpeg (self , images :list , quality :int = 1 ):
224
+ async def jpeg (self , images :List [ str ] , quality :int = 1 ) -> PxlObject :
208
225
"""
209
226
Turns the provided images into lower quality
210
227
@@ -219,9 +236,9 @@ async def jpeg(self, images:list, quality:int=1):
219
236
'images' : images ,
220
237
'quality' : quality
221
238
}
222
- return await self .get_img ('jpeg' , body )
239
+ return await self ._get_img ('jpeg' , body )
223
240
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 :
225
242
"""
226
243
Turns the provided images into images with the snap filter provided if a face is detected
227
244
@@ -237,15 +254,15 @@ async def snapchat(self, filter:str, images:list, filters:list=None):
237
254
if self .stop_on_error :
238
255
raise InvalidFilter (f'Flag { filter .lower ()} not a valid filter' )
239
256
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' )
241
258
242
259
body = {
243
260
'images' : images ,
244
261
'filters' : filters
245
262
}
246
- return await self .get_img (f'snapchat/{ filter } ' , body )
263
+ return await self ._get_img (f'snapchat/{ filter } ' , body )
247
264
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 :
249
266
"""
250
267
Turns the provided images into images with a filter applied to the eyes of faces detected
251
268
@@ -259,17 +276,17 @@ async def eyes(self, eyes:str, images:list, filters:list=None):
259
276
"""
260
277
if not eyes .lower () in self .valid_eyes :
261
278
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' )
263
280
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')
265
282
266
283
body = {
267
284
'images' : images ,
268
285
'filters' : filters
269
286
}
270
- return await self .get_img (f'eyes/{ eyes } ' , body )
287
+ return await self ._get_img (f'eyes/{ eyes } ' , body )
271
288
272
- async def thonkify (self , text :str ):
289
+ async def thonkify (self , text :str ) -> PxlObject :
273
290
"""
274
291
Turns the provided text into an image with that text made up of thonks
275
292
@@ -282,9 +299,9 @@ async def thonkify(self, text:str):
282
299
body = {
283
300
'text' : text
284
301
}
285
- return await self .get_img ('thonkify' , body )
302
+ return await self ._get_img ('thonkify' , body )
286
303
287
- async def sonic (self , text :str ):
304
+ async def sonic (self , text :str ) -> PxlObject :
288
305
"""
289
306
Turns the provided text into an image with sonic saying the provided text
290
307
@@ -298,14 +315,38 @@ async def sonic(self, text:str):
298
315
if self .stop_on_error :
299
316
raise TooManyCharacters ("Too many characters used for the sonic endpoint" )
300
317
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" )
302
319
303
320
body = {
304
321
'text' : text
305
322
}
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 )
307
348
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 :
309
350
"""
310
351
Evaluates code
311
352
@@ -323,9 +364,9 @@ async def imagescript(self, version:str, code:str, inject=None, timeout:int=1000
323
364
'inject' : inject ,
324
365
'timeout' : timeout
325
366
}
326
- return await self .get_img (f'imagescript/{ version } ' , body )
367
+ return await self ._get_img (f'imagescript/{ version } ' , body )
327
368
328
- async def imagescript_version (self ):
369
+ async def imagescript_version (self ) -> PxlObject :
329
370
"""
330
371
Gives you the available versions for imagescript
331
372
@@ -336,9 +377,9 @@ async def imagescript_version(self):
336
377
`PxlObject`
337
378
"""
338
379
body = {}
339
- return await self .get_text ('imagescript/versions' , body )
380
+ return await self ._get_text ('imagescript/versions' , body )
340
381
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 :
342
383
"""
343
384
Looks for images with provided query
344
385
@@ -354,26 +395,26 @@ async def image_search(self, query:str, safeSearch:str='strict', meta:bool=False
354
395
if self .stop_on_error :
355
396
raise TooManyCharacters ("Too many characters used for the image_search endpoint" )
356
397
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" )
358
399
if not safeSearch .lower () in self .safe_search :
359
400
if self .stop_on_error :
360
401
raise InvalidSafety ("Invalid safety level for the image_search endpoint" )
361
402
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" )
363
404
364
405
body = {
365
406
'query' : query ,
366
407
'safeSearch' : safeSearch ,
367
408
'meta' : meta
368
409
}
369
- return await self .get_text ('image_search' , body )
410
+ return await self ._get_text ('image_search' , body )
370
411
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 :
372
413
"""
373
414
Screenshots the webpage provided
374
415
375
416
# Parameters:
376
- `url (string): The website to screenshot
417
+ `url (string) -> PxlObject : The website to screenshot
377
418
`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.
378
419
`locale (string)`: The locale to set the browser to
379
420
`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
396
437
'theme' : theme ,
397
438
'timeout' : timeout
398
439
}
399
- return await self .get_img ('screenshot' , body )
440
+ return await self ._get_img ('screenshot' , body )
400
441
401
- async def web_search (self , query :str , safeSearch :str = 'strict' ):
442
+ async def web_search (self , query :str , safeSearch :str = 'strict' ) -> PxlObject :
402
443
"""
403
444
Searches for the querie provided
404
445
405
446
# Parameters:
406
- `url (string): The website to screenshot
447
+ `url (string) -> PxlObject : The website to screenshot
407
448
`safeSearch (string)`: What safe search setting to use
408
449
409
450
# Returns:
@@ -413,15 +454,15 @@ async def web_search(self, query:str, safeSearch:str='strict'):
413
454
if self .stop_on_error :
414
455
raise TooManyCharacters ("Too many characters used for the web_search endpoint" )
415
456
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" )
417
458
if not safeSearch .lower () in self .safe_search :
418
459
if self .stop_on_error :
419
460
raise InvalidSafety ("Invalid safety level for the web_search endpoint" )
420
461
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" )
422
463
423
464
body = {
424
465
'query' : query ,
425
466
'safeSearch' : safeSearch
426
467
}
427
- return await self .get_text ('web_search' , body )
468
+ return await self ._get_text ('web_search' , body )
0 commit comments