diff options
| author | Colin Wilk <colin.wilk@tum.de> | 2023-10-01 18:41:45 +0200 |
|---|---|---|
| committer | Colin Wilk <colin.wilk@tum.de> | 2023-10-01 18:41:45 +0200 |
| commit | ed80b5ce0b610da7511634a1ced5bd1d25c9f39b (patch) | |
| tree | 907b99ea8ab4669687f38e5ccf5593f68d2cc01e /src/lib/szurubooru.py | |
| parent | 4329cb0a3b8eec858762755a38c6a3e196876c0e (diff) | |
| download | szuruboorupy-ed80b5ce0b610da7511634a1ced5bd1d25c9f39b.tar.gz szuruboorupy-ed80b5ce0b610da7511634a1ced5bd1d25c9f39b.zip | |
Add Szurubooru __delete helper function
Signed-off-by: Colin Wilk <colin.wilk@tum.de>
Diffstat (limited to 'src/lib/szurubooru.py')
| -rw-r--r-- | src/lib/szurubooru.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lib/szurubooru.py b/src/lib/szurubooru.py index 8649368..7438f76 100644 --- a/src/lib/szurubooru.py +++ b/src/lib/szurubooru.py @@ -369,6 +369,7 @@ class Szurubooru: requests_get: int = 0 requests_post: int = 0 requests_put: int = 0 + requests_delete: int = 0 def __init__(self, url: str, token: str, verify: bool = True): self.url = url @@ -391,13 +392,14 @@ class Szurubooru: return wrapper @staticmethod - def __count_stats(get: int = 0, post: int = 0, put: int = 0): + def __count_stats(get: int = 0, post: int = 0, put: int = 0, delete: int = 0): def function_wrapper(func): @functools.wraps(func) def wrapper(self, **kwargs): self.requests_get += get self.requests_post += post self.requests_put += put + self.requests_delete += delete return func(self, **kwargs) return wrapper @@ -433,6 +435,17 @@ class Szurubooru: data=json.dumps(params), ) + @__count_stats(delete=1) + @__raise_szurubooru_exception + def __delete(self, path: str, params: dict) -> r.Response: + return r.delete( + f"{self.url}{path}", + timeout=15, + verify=self.verify, + headers=self.header, + data=json.dumps(params), + ) + def __map_tag_resource_response(self, res: r.Response, name: str = "") -> Tag: """Maps the requests response from the Szurubooru REST API to the Tag dataclass. |