Skip to content

Commit 0bc9fe9

Browse files
author
Dhruva Shaw
committed
finished, ready for the update
1 parent 02032ac commit 0bc9fe9

18 files changed

Lines changed: 134 additions & 51 deletions

README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Key Features
2323
Installing
2424
----------
2525

26-
**Python 3.8 or higher is required**
26+
**Python 3.9 or higher is required**
2727

2828
To install the library, you can just run the following command:
2929

@@ -50,7 +50,7 @@ To install the development version, do the following:
5050

5151
.. code:: sh
5252
53-
$ git clone https://github.com/Dhruvacube/fluxpoint.py
53+
$ git clone https://github.com/Creatrix-Net/fluxpoint.py
5454
$ cd fluxpoint.py
5555
$ python3 -m pip install -U .[speed]
5656
@@ -65,23 +65,23 @@ Quick Example
6565
import sys
6666
6767
# setting up the fluxpoint client handler
68-
a = FluxpointClient(api_token="get api token from https://fluxpoint.dev/api/access")
68+
a = FluxpointClient(api_token="get api token from fluxpoint.dev/api/access")
6969
7070
# setting up the windows loop policy according to the operating system
7171
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
7272
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
7373
74-
# getting the image url of AZURLANE image
75-
print(asyncio.run(a.azurlane()))
74+
# getting the random dadjoke
75+
print(asyncio.run(a.dadjoke()))
7676
7777
78-
You can find more examples in the `examples directory <https://github.com/Dhruvacube/fluxpoint.py/tree/master/examples>`_.
78+
You can find more examples in the `examples directory <https://github.com/Creatrix-Net/fluxpoint.py/tree/master/examples>`_.
7979

8080
Links
8181
------
8282

83-
- `Documentation <https://fluxpointpy.readthedocs.io/en/latest/>`_
83+
- `Documentation <https://fluxpointpy.dhruvashaw.in/en/latest/>`_
8484
- `Official Support Discord Server <https://discord.gg/vfXHwS3nmQ>`_
8585
- `Official Fluxpoint server <https://discord.gg/fluxpoint>`_
8686
- `Get Fluxpoint api access <https://fluxpoint.dev/api/access>`_
87-
- `Official Fluxpoint api docs <https://bluedocs.page/fluxpoint-api>`_
87+
- `Official Fluxpoint api docs <https://docs.fluxpoint.dev/api>`_

examples/custom_generator_image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from fluxpoint import FluxpointClient, ImageUrl, Square, Text
55

66
# setting up the fluxpoint client handler
7-
a = FluxpointClient(api_token="get api token from https://fluxpoint.dev/api/access")
7+
a = FluxpointClient(api_token="get api token from fluxpoint.dev/api/access")
88

99
# setting up the windows loop policy according to the operating system
1010
if sys.platform.startswith(('win32', 'cygwin')):
1111
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
1212

1313
# getting the image bytes data
14-
data = asyncio.run(a.customimage(
15-
type="bitmap",
14+
data = asyncio.run(a.custom(
15+
imgtype="bitmap",
1616
width=2000,
1717
height=2000,
1818
color="#7289da",

examples/custom_generator_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import asyncio
22
import sys
33

4-
from fluxpoint import FluxpointClient
4+
from fluxpoint import Tests
5+
from fluxpoint.vars import ImageType
56

67
# setting up the fluxpoint client handler
7-
a = FluxpointClient(api_token="get api token from https://fluxpoint.dev/api/access")
8+
a = Tests(api_token="get api token from fluxpoint.dev/api/access")
89

910
# setting up the windows loop policy according to the operating system
1011
if sys.platform.startswith(('win32', 'cygwin')):
1112
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
1213

1314
# getting the image bytes data
14-
data = asyncio.run(a.test())
15+
data = asyncio.run(a.imagen(ImageType.PNG))
1516

1617
#saving the image into a file
1718
with open('custom_generator_test.png', 'wb+') as f:

examples/simple_request.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
from fluxpoint import FluxpointClient
12
import asyncio
23
import sys
34

4-
from fluxpoint import FluxpointClient
5-
65
# setting up the fluxpoint client handler
7-
a = FluxpointClient(api_token="get api token from https://fluxpoint.dev/api/access")
6+
a = FluxpointClient(api_token="get api token from fluxpoint.dev/api/access")
87

98
# setting up the windows loop policy according to the operating system
10-
if sys.platform.startswith(('win32', 'cygwin')):
9+
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
1110
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
1211

13-
# getting the image url of AZURLANE image
14-
print(asyncio.run(a.azurlane()))
12+
# getting the random dadjoke
13+
print(asyncio.run(a.dadjoke()))

examples/welcome_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fluxpoint import FluxpointClient, WelcomeConfig
55

66
# setting up the fluxpoint client handler
7-
a = FluxpointClient(api_token="get api token from https://fluxpoint.dev/api/access")
7+
a = FluxpointClient(api_token="get api token from fluxpoint.dev/api/access")
88

99
# setting up the windows loop policy according to the operating system
1010
if sys.platform.startswith(('win32', 'cygwin')):

fluxpoint/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from .paths import Gifs, Images, NSFW, Misc, Welcome, ImageGenerator
1+
from .paths import Convert,Color,CustomImage,Template,ImgAndGif,Lists,Minecraft,Misc,Utility
22

33

4-
class FluxpointClient(Gifs, Images, NSFW, Misc, Welcome, ImageGenerator):
4+
class FluxpointClient(Convert,Color,CustomImage,Template,ImgAndGif,Lists,Minecraft,Misc,Utility):
55
'''The fluxpoint client where all the api routes are located'''
66

77
def __str__(self) -> str:

fluxpoint/errors.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from enum import EnumType
2+
from typing import Any
3+
4+
15
class HttpException(Exception):
26
"""
37
Fluxpoint base exception class use this base class to catch any Fluxpoint errors.
@@ -63,3 +67,19 @@ class InvalidFeature(Exception):
6367
"""
6468
The feature chosen is not valid
6569
"""
70+
71+
def paramEnumValidCheck(parameter: Any, class2check: EnumType) -> None:
72+
"""
73+
Checks if the ``parameter`` is a member of ``class2check`` :class::`Enum` and check if ``parameter`` is a instance of ``class2check`` :class::`Enum`
74+
75+
:raises ValueError: if ``parameter`` is not a member of ``class2check``
76+
77+
:param parameter: The parameter to check
78+
:type parameter: :class:`Any`
79+
:param class2check: The class to check
80+
:type class2check: :class:`EnumType`
81+
"""
82+
if isinstance(parameter, class2check):
83+
raise Exception("Category must be a instance of NSFWImage or NSFWGif")
84+
if parameter not in class2check:
85+
raise ValueError(f"{parameter} is not a valid in {class2check}")

fluxpoint/http.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ def __init__(self, api_token: str) -> None:
2424

2525
async def request(
2626
self,
27-
method: RequestTypes,
28-
endpoint: str,
29-
params: Optional[dict] = None,
30-
json: Optional[dict] = None,
31-
data: Optional[str] = None,
32-
headers: Optional[dict] = None,
33-
_base_url: Optional[Union[str, URL]] = 'https://api.fluxpoint.dev/',
34-
retry: bool = True,
35-
return_json: bool = True,
36-
return_bytes: bool = False,
37-
retry_times: int = 1
27+
method: RequestTypes,
28+
endpoint: str,
29+
params: Optional[dict] = None,
30+
json: Optional[dict] = None,
31+
data: Optional[str, aiohttp.FormData] = None,
32+
headers: Optional[dict] = None,
33+
_base_url: Optional[Union[str, URL]] = 'https://api.fluxpoint.dev/',
34+
retry: bool = True,
35+
return_json: bool = True,
36+
return_bytes: bool = False,
37+
retry_times: int = 1
3838
) -> Union[aiohttp.ClientResponse, dict, io.IOBase]:
3939
"""Makes an API request
4040
@@ -62,7 +62,7 @@ async def request(
6262
return await self.request(method, endpoint, json, headers, retry=retry_times <= 10, retry_times=retry_times+1)
6363

6464
try:
65-
result = await response.json(content_type="application/json") if return_json else (await response.read()if return_bytes else response)
65+
result = await response.json(content_type="application/json") if return_json else (await response.read() if return_bytes else response)
6666
if response.status == 200:
6767
return result
6868
result = await response.json(content_type="application/json") if not isinstance(result, dict) else result

fluxpoint/paths/color.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from urllib.parse import urlencode
21
from typing import Optional, AsyncGenerator
32

4-
from fluxpoint import ParameterError
53
from fluxpoint.vars import RequestTypes
64
from fluxpoint.http import BaseHTTP
75

fluxpoint/paths/convert.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from fluxpoint.errors import paramEnumValidCheck
12
from fluxpoint.vars import RequestTypes
23
from fluxpoint.http import BaseHTTP
4+
from fluxpoint.vars import ImageType
5+
import io
6+
import aiohttp
37

48
class Convert(BaseHTTP):
59
"""Convert Api endpoints documented in https://docs.fluxpoint.dev/api/endpoints/convert
@@ -9,4 +13,64 @@ def __init__(self, *args, **kwargs) -> None:
913
self.__baseurl = '/convert'
1014
super().__init__(*args, **kwargs)
1115

16+
@staticmethod
17+
def imgdata2form(image: io.IOBase) -> aiohttp.FormData:
18+
"""
19+
Converts image data to formdata
1220
21+
:param image: image data
22+
:type image: :class:`io.IOBase`
23+
:return: aiohttp form data class
24+
:rtype: :class:`aiohttp.FormData`
25+
"""
26+
form = aiohttp.FormData()
27+
form.add_field("file", image, filename="upload", content_type="application/octet-stream")
28+
return form
29+
30+
async def html2markdown(self, html:str) -> str:
31+
"""
32+
Convert html to markdown
33+
:param html: The html to convert
34+
:type html: str
35+
:return: The converted html to markdown
36+
:rtype: str
37+
"""
38+
return (await self.request(RequestTypes.POST, f'{self.__baseurl}/html-markdown',data=html)).get('markdown')
39+
40+
async def markdown2html(self, markdown:str) -> str:
41+
"""
42+
Convert markdown to html
43+
:param markdown: The markdown to convert
44+
:type markdown: str
45+
:return: The converted markdown to html
46+
:rtype: str
47+
"""
48+
return (await self.request(RequestTypes.POST, f'{self.__baseurl}/markdown-html',data=markdown)).get('html')
49+
50+
async def image2type(self, image: io.IOBase, imgtype: ImageType, quality: int = 100) -> io.IOBase:
51+
"""
52+
Convert an image to png/jpg/webp
53+
54+
:raises ValueError: When the ``quality`` parameter is not between ``1`` and ``100``
55+
56+
:param image: The image to convert
57+
:type image: :class:`io.IOBase`
58+
:param quality: The quality to convert to
59+
:type quality: int
60+
:param imgtype: The type to convert to
61+
:type imgtype: :class:`ImageType`
62+
63+
:return: The converted image
64+
:rtype: :class:`io.IOBase`
65+
"""
66+
if quality > 100 or quality < 1:
67+
raise ValueError("The return quality value must be between 1 and 100")
68+
paramEnumValidCheck(image, ImageType)
69+
return await self.request(
70+
RequestTypes.POST,
71+
f'{self.__baseurl}/image-{imgtype.value}',
72+
data=self.__class__.imgdata2form(image),
73+
return_bytes=True,
74+
return_json=False,
75+
params={"quality": quality}
76+
)

0 commit comments

Comments
 (0)