dswebhook 0.2.2__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.
dswebhook/__init__.py
ADDED
dswebhook/dswebhook.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
from exceptions import (
|
|
4
|
+
InvalidURL, SchemaError, AlreadyExists, NoSuchID,
|
|
5
|
+
ContentTooLarge, ConnectionError, BadRequest, InternalServerError, HTTPError
|
|
6
|
+
)
|
|
7
|
+
urlr = {}
|
|
8
|
+
|
|
9
|
+
def init(url:str, id=1):
|
|
10
|
+
'''specify webhook url and id (Deafult 1)'''
|
|
11
|
+
global urlr
|
|
12
|
+
if not url:
|
|
13
|
+
raise InvalidURL(f"MUST BE VALID URL FOR ID {id}")
|
|
14
|
+
if id in urlr:
|
|
15
|
+
raise AlreadyExists(f"{id} ALREADY EXSISTS")
|
|
16
|
+
urlr[id] = url
|
|
17
|
+
|
|
18
|
+
def send(content:str, ids, statCode:bool=False, flush:bool = False):
|
|
19
|
+
'''Send content to specified webhook'''
|
|
20
|
+
global urlr
|
|
21
|
+
if not urlr:
|
|
22
|
+
raise InvalidURL("FIRST SPECIFY URL USING init(url, id) MODULE")
|
|
23
|
+
if len(content) > 2000:
|
|
24
|
+
raise ContentTooLarge(f"TOO LARGE CONTENT FOR {ids}")
|
|
25
|
+
data = {
|
|
26
|
+
"content":content
|
|
27
|
+
}
|
|
28
|
+
if urlr.get(ids) == None:
|
|
29
|
+
raise NoSuchID(f"NOT FOUND {ids}")
|
|
30
|
+
try:
|
|
31
|
+
a = requests.post(urlr.get(ids), json=data)
|
|
32
|
+
except requests.exceptions.ConnectionError:
|
|
33
|
+
raise ConnectionError(f"CONNECTION ERROR FOR {ids} PLEASE CHECK CONNETCTION AND URL FOR ANY ERRORS")
|
|
34
|
+
except requests.exceptions.MissingSchema:
|
|
35
|
+
raise SchemaError(f"MUST BE WITH https:// OR http:// IF HTTPS NOT SUPPORTED FOR {ids}")
|
|
36
|
+
|
|
37
|
+
if a.status_code == 400:
|
|
38
|
+
raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400) FOR {ids}")
|
|
39
|
+
|
|
40
|
+
if a.status_code == 500:
|
|
41
|
+
raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500) FOR {ids}")
|
|
42
|
+
|
|
43
|
+
if not a.ok:
|
|
44
|
+
raise HTTPError(f"SERVER RETURNED NOT 2xx RESPONSE {a.status_code} FOR {ids}")
|
|
45
|
+
|
|
46
|
+
if statCode:
|
|
47
|
+
print(a.status_code, f"FOR {ids}")
|
|
48
|
+
|
|
49
|
+
if flush:
|
|
50
|
+
if a.text == "":
|
|
51
|
+
print(f"NOTHING FROM SERVER FOR {ids}")
|
|
52
|
+
else:
|
|
53
|
+
print(a.text, f"FOR {ids}")
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
exceptions.py,sha256=_Q-HVPIQm2nmCXg64zw82acXPlTFdbBAeSUPqKW3xdA,760
|
|
2
|
+
dswebhook/__init__.py,sha256=vHcdyBboIrVU5gOa1aUfZvA9PcJJzsUyllKqGb8lywI,65
|
|
3
|
+
dswebhook/dswebhook.py,sha256=BkbKqnXPx3OgVbzO-Orj3ujeI74aKppeoUf22_XIOOg,1827
|
|
4
|
+
dswebhook-0.2.2.dist-info/licenses/LICENSE,sha256=XAgqcFGVsl4wvMXTvw9WgdH-b6gF13HPvRRrEdQh874,1084
|
|
5
|
+
dswebhook-0.2.2.dist-info/METADATA,sha256=Ojrhifnud2RAVkDzRkvfEFQXg4CX4cChTvwqMz25nB8,221
|
|
6
|
+
dswebhook-0.2.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
dswebhook-0.2.2.dist-info/top_level.txt,sha256=nkxqO8M_wrbBO6Rm6v_xIZ20U79WRpDp4RpUKwu3GjY,21
|
|
8
|
+
dswebhook-0.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Beks1k
|
|
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.
|
exceptions.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class BadRequest(Exception):
|
|
2
|
+
'''When 400 hits in'''
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
class InternalServerError(Exception):
|
|
6
|
+
'''When 500 hits in'''
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class InvalidURL(Exception):
|
|
10
|
+
'''When Invalid url is given'''
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
class ContentTooLarge(Exception):
|
|
14
|
+
'''When Given content bigger than 2000'''
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
class ConnectionError(Exception):
|
|
18
|
+
'''When Connection error accures such as no inter net etc.'''
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
class SchemaError(Exception):
|
|
22
|
+
'''When schema not right'''
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
class NoSuchID(Exception):
|
|
26
|
+
'''When id is not found in urlr'''
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
class AlreadyExists(Exception):
|
|
30
|
+
'''When id is already exists in urlr'''
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
class HTTPError(Exception):
|
|
34
|
+
'''When other HTTP error accures'''
|
|
35
|
+
pass
|