cataas 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cataas/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from .core import cat, catgif, catgif_says, cats, catsays, count, tags
2
+ from .premade import filtercat, randomtype
cataas/core.py ADDED
@@ -0,0 +1,177 @@
1
+ import requests
2
+ import sys, io
3
+ from urllib.parse import quote
4
+ sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8')
5
+
6
+ base_url = 'https://cataas.com'
7
+
8
+ def cat(tag=None, width=None, height=None, filter=None, **kwargs) -> str:
9
+ """_summary_
10
+
11
+ Args:
12
+ tag (_type_, optional): _description_. Defaults to None.
13
+ width (_type_, optional): _description_. Defaults to None.
14
+ height (_type_, optional): _description_. Defaults to None.
15
+ filter (_type_, optional): _description_. Defaults to None.
16
+
17
+ Returns:
18
+ str: _Cat image URL_
19
+ """
20
+ if tag and tag == str:
21
+ request_url = f'{base_url}/cat/{quote(tag)}'
22
+ else:
23
+ request_url = f'{base_url}/cat'
24
+
25
+ raw_params = {
26
+ 'width': width,
27
+ 'height': height,
28
+ 'filter': filter,
29
+ 'json': 'true',
30
+ **kwargs
31
+ }
32
+ params = {k: v for k, v in raw_params.items() if v is not None}
33
+ response = requests.get(request_url, params=params)
34
+
35
+ response.raise_for_status()
36
+
37
+ data = response.json()
38
+ url = data['url']
39
+ return url
40
+
41
+ def catgif(**kwargs) -> str:
42
+ """
43
+ Returns a random cat gif URL.
44
+ """
45
+ request_url = f'{base_url}/cat/gif'
46
+
47
+ raw_params = {
48
+ 'json': 'true',
49
+ **kwargs
50
+ }
51
+ params = {k: v for k, v in raw_params.items() if v is not None}
52
+ response = requests.get(request_url, params=params)
53
+
54
+ response.raise_for_status()
55
+
56
+ data = response.json()
57
+ url = data['url']
58
+ return url
59
+
60
+ def catgif_says(text: str, fontColor=None, fontSize=None, filter=None, **kwargs) -> str:
61
+ """_summary_
62
+
63
+ Args:
64
+ text (str): _description_
65
+ fontColor (_type_, optional): _description_. Defaults to None.
66
+ fontSize (_type_, optional): _description_. Defaults to None.
67
+ filter (_type_, optional): _description_. Defaults to None.
68
+
69
+ Returns:
70
+ str: _Cat gif saying text URL_
71
+ """
72
+ request_url = f'{base_url}/cat/gif/says/{quote(text)}'
73
+
74
+ raw_params = {
75
+ 'fontColor': fontColor,
76
+ 'fontSize': fontSize,
77
+ 'filter': filter,
78
+ 'json': 'true',
79
+ **kwargs
80
+ }
81
+ params = {k: v for k, v in raw_params.items() if v is not None}
82
+ response = requests.get(request_url, params=params)
83
+
84
+ response.raise_for_status()
85
+
86
+ data = response.json()
87
+ url = data['url']
88
+ return url
89
+
90
+ def catsays(text: str, tag=None, width=None, height=None, filter=None, **kwargs) -> str:
91
+ """_summary_
92
+
93
+ Args:
94
+ tag (_type_, optional): _description_. Defaults to None.
95
+ width (_type_, optional): _description_. Defaults to None.
96
+ height (_type_, optional): _description_. Defaults to None.
97
+ filter (_type_, optional): _description_. Defaults to None.
98
+
99
+ Returns:
100
+ str: _Cat image URL_
101
+ """
102
+ if tag and tag == str:
103
+ request_url = f'{base_url}/cat/{quote(tag)}/says/{quote(text)}'
104
+ else:
105
+ request_url = f'{base_url}/cat/says/{text}'
106
+
107
+ raw_params = {
108
+ 'width': width,
109
+ 'height': height,
110
+ 'filter': filter,
111
+ 'json': 'true',
112
+ **kwargs
113
+ }
114
+ params = {k: v for k, v in raw_params.items() if v is not None}
115
+ response = requests.get(request_url, params=params)
116
+
117
+ response.raise_for_status()
118
+
119
+ data = response.json()
120
+ url = data['url']
121
+ return url
122
+
123
+ def cats(limit: int, tags: list[str] = None, **kwargs) -> list[str]:
124
+ """_summary_
125
+
126
+ Args:
127
+ limit (int): _description_
128
+ tags (list[str], optional): _description_. Defaults to None.
129
+
130
+ Returns:
131
+ list[str]: _List of cat images_
132
+ """
133
+ request_url = f'{base_url}/api/cats'
134
+
135
+ raw_params = {
136
+ 'limit': limit,
137
+ 'json': 'true',
138
+ **kwargs
139
+ }
140
+ if tags and tags == str:
141
+ formatted_tags = ','.join(tags)
142
+ raw_params['tags'] = formatted_tags
143
+ params = {k: v for k, v in raw_params.items() if v is not None}
144
+ response = requests.get(request_url, params=params)
145
+
146
+ response.raise_for_status()
147
+
148
+ data = response.json()
149
+ urls = [f'{base_url}/cat/{cat['id']}' for cat in data]
150
+ return urls
151
+
152
+ def count(print_amount: bool = False):
153
+ """Returns the amount of cats uploaded in the CataaS REST API"""
154
+ request_url = f'{base_url}/api/count'
155
+ response = requests.get(request_url)
156
+ response.raise_for_status()
157
+
158
+ data = response.json()
159
+ amount = data['count']
160
+
161
+ if print_amount == True:
162
+ print(f'Amount of cats uploaded: {amount}')
163
+ else:
164
+ return amount
165
+
166
+ def tags(print_amount: bool = False):
167
+ """Returns all tags that have been used in uploaded cat images (note that this will be very big)"""
168
+ request_url = f'{base_url}/api/tags'
169
+ response = requests.get(request_url)
170
+ response.raise_for_status()
171
+
172
+ alltags: list[str] = response.json()
173
+
174
+ if print_amount == True:
175
+ print(f'All tags in uploaded cats: {alltags}')
176
+ else:
177
+ return alltags
cataas/premade.py ADDED
@@ -0,0 +1,33 @@
1
+ import requests
2
+ import random
3
+
4
+ base_url = 'https://cataas.com'
5
+ json_headers = {'Accept': 'application/json'}
6
+
7
+ def randomtype():
8
+ """Returns a cat image with a random shape type"""
9
+ types = [
10
+ 'square',
11
+ 'medium',
12
+ 'small',
13
+ 'xsmall'
14
+ ]
15
+ response = requests.get(f'{base_url}/cat?type={random.choice(types)}', headers=json_headers)
16
+ response.raise_for_status()
17
+
18
+ data = response.json()
19
+ url = data['url']
20
+ return url
21
+
22
+ def filtercat():
23
+ """Returns a cat image with either the mono filter or negate filter"""
24
+ filters = [
25
+ 'mono',
26
+ 'negate'
27
+ ]
28
+ response = requests.get(f'{base_url}/cat?filter={random.choice(filters)}', headers=json_headers)
29
+ response.raise_for_status()
30
+
31
+ data = response.json()
32
+ url = data['url']
33
+ return url
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: cataas
3
+ Version: 0.1.0
4
+ Summary: A unofficial Python wrapper for the CataaS REST API.
5
+ Author-email: happycappa <280617573+happycappa@users.noreply.github.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/happycappa/cataas
8
+ Project-URL: Source, https://github.com/happycappa/cataas/tree/main/src/cataas
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.34.2
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest; extra == "dev"
15
+ Dynamic: license-file
16
+
17
+ # Unofficial CataaS Python Wrapper
18
+ This is an unofficial Python wrapper for the CataaS _(Cat as a Service)_ REST API.
19
+ Here is it's offical website: https://cataas.com/
20
+
21
+ I created this since i'm pretty bored and I don't wanna keep having to use the python [requests](https://github.com/psf/requests) package everytime I want to use the CataaS API!
22
+
23
+ ## Why would I want to use this?
24
+ You can use this, like me, to have a shortcut on using the CataaS API in Python without needing to
25
+ import the [requests](https://github.com/psf/requests) library everytime, which i'd say is a better upgrade than the harder way.
26
+
27
+ # Usage
28
+ Here's some examples on how to use this package:
29
+
30
+ 1. Getting a cat image
31
+ ```python
32
+ import cataas
33
+
34
+ cat = cataas.cat()
35
+ print(cat)
36
+
37
+ # Returns a normal cat image by URL
38
+
39
+ cat = cataas.catsays('Hello world!')
40
+ print(cat)
41
+
42
+ # Returns a cat image that has text by URL
43
+ # Filters are supported too!
44
+
45
+ cat = cataas.cat(width=500, height=700) # Kwargs are included
46
+ print(cat)
47
+
48
+ # Returns a cat image thats (probably) exactly 500 by 700 pixels!
49
+ ```
50
+
51
+ 2. Getting a cat gif
52
+ ```python
53
+ import cataas
54
+
55
+ cat = cataas.catgif()
56
+ print(cat)
57
+
58
+ # Returns a normal cat gif by URL
59
+ # Note: The normal catgif function doesn't support filters, but the says version does!
60
+
61
+ cat = cataas.catgif_says('Hello world!')
62
+ print(cat)
63
+
64
+ # Returns a cat gif that has text by URL
65
+ ```
66
+
67
+ Other functions are included too but i'm too lazy to explain them.
68
+
69
+ # Credits
70
+
71
+ 1. me (happycappa)
72
+ 2. no one else (this is a solo package)
@@ -0,0 +1,8 @@
1
+ cataas/__init__.py,sha256=nTY0EBdZv9seXcuS0VmzJmCUi6MaRTLVFepGvlkcrOQ,114
2
+ cataas/core.py,sha256=2oc1G8X58VmK855lYZTdd-xsK0WWX1Cc8VbdGtX5Quk,5073
3
+ cataas/premade.py,sha256=2yd7yp3DoAy62g5nyI3H6tPM8mpV15ldxSQ5cRSCuks,844
4
+ cataas-0.1.0.dist-info/licenses/LICENSE,sha256=6zogNZM0Od9p4HkkeGWcOn8IK4Aj3wP4KcU6QpsrgkU,1088
5
+ cataas-0.1.0.dist-info/METADATA,sha256=FUvEhocNDrG4YhgQna657vaDHB-4U2j0FSyjsquWO_o,2104
6
+ cataas-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ cataas-0.1.0.dist-info/top_level.txt,sha256=_-dAgmny_jSSCB2FOmrcJ-290T1g1u1avfnXjadqAws,7
8
+ cataas-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 happycappa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ cataas