diff options
| author | Colin Wilk <colin.wilk@tum.de> | 2023-10-01 19:46:53 +0200 |
|---|---|---|
| committer | Colin Wilk <colin.wilk@tum.de> | 2023-10-01 19:46:53 +0200 |
| commit | 45301553e15e95afe3139f8efa4885c1462d436d (patch) | |
| tree | ba8daa69798289e61682d55f429908fdfec3a8e4 /src | |
| parent | 2c20f1ce8d7ee990af6d7c24d41bc32aa08c768b (diff) | |
| download | szuruboorupy-45301553e15e95afe3139f8efa4885c1462d436d.tar.gz szuruboorupy-45301553e15e95afe3139f8efa4885c1462d436d.zip | |
Move tag into dataclass Module
Additionally change the description of the Tag modules (and other
dataclass modules) to match the description from the Szurubooru API
reference.
Signed-off-by: Colin Wilk <colin.wilk@tum.de>
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/dataclasses.py | 46 | ||||
| -rw-r--r-- | src/lib/szurubooru.py | 2 | ||||
| -rw-r--r-- | src/lib/tag.py | 19 |
3 files changed, 47 insertions, 20 deletions
diff --git a/src/lib/dataclasses.py b/src/lib/dataclasses.py new file mode 100644 index 0000000..16413b7 --- /dev/null +++ b/src/lib/dataclasses.py @@ -0,0 +1,46 @@ +""" +Module for collection of dataclasses that map Szurubooru objects to python classes +""" + + +from dataclasses import dataclass, field +from typing import List + + +@dataclass +class Tag: + """A single tag. Tags are used to let users search for posts. + + The Szurubooru structure: + .. code-block:: JSON + { + "version": <version>, + "names": <names>, + "category": <category>, + "implications": <implications>, + "suggestions": <suggestions>, + "creationTime": <creation-time>, + "lastEditTime": <last-edit-time>, + "usages": <usage-count>, + "description": <description> + } + + **Field meaning** + - `<version>`: resource version. + - `<names>`: a list of tag names (aliases). Tagging a post with any name will + automatically assign the first name from this list. + - `<category>`: the name of the category the given tag belongs to. + - `<implications>`: a list of implied tags, serialized as micro tag resource. + - `<suggestions>`: a list of suggested tags, serialized as micro tag resource. + - `<creation-time>`: time the tag was created, formatted as per RFC 3339. + - `<last-edit-time>`: time the tag was edited, formatted as per RFC 3339. + - `<usage-count>`: the number of posts the tag was used in. + - `<description>`: the tag description (instructions how to use, history etc.) + """ + + name: str + version: int = -1 + description: str = "" + category: str = "General" + implications: List[str] = field(default_factory=list) + suggestions: List[str] = field(default_factory=list) diff --git a/src/lib/szurubooru.py b/src/lib/szurubooru.py index 03261dd..1219cfb 100644 --- a/src/lib/szurubooru.py +++ b/src/lib/szurubooru.py @@ -9,7 +9,7 @@ Szurubooru Library is used for communicating with a Szurubooru instance through """ -from lib.tag import Tag +from lib.dataclasses import Tag import requests as r from typing import List import json diff --git a/src/lib/tag.py b/src/lib/tag.py deleted file mode 100644 index d4f11ed..0000000 --- a/src/lib/tag.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Tag Module for mapping Szurubooru posts to tags -""" - - -from dataclasses import dataclass, field -from typing import List - - -@dataclass -class Tag: - """Data class representing a tag""" - - name: str - version: int = -1 - description: str = "" - category: str = "General" - implications: List[str] = field(default_factory=list) - suggestions: List[str] = field(default_factory=list) |