lanraragi-api 0.0.1__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.

Potentially problematic release.


This version of lanraragi-api might be problematic. Click here for more details.

@@ -0,0 +1 @@
1
+ from .lanraragi import LANrargiAPI
@@ -0,0 +1,7 @@
1
+ from .archive import ArchiveAPI
2
+ from .category import CategoryAPI
3
+ from .database import DatabaseAPI
4
+ from .minion import MinionAPI
5
+ from .other import OtherAPI
6
+ from .search import SearchAPI
7
+ from .shinobu import ShinobuAPI
@@ -0,0 +1,48 @@
1
+ from script_house.utils import JsonUtils
2
+ import requests
3
+
4
+ from ..common.base import BaseAPICall
5
+ from ..common.entity import Archive, Category
6
+
7
+
8
+ class ArchiveAPI(BaseAPICall):
9
+ def get_archive_metadata(self, id: str) -> Archive:
10
+ """
11
+ Get Metadata (title, tags) for a given Archive.
12
+ :param id: ID of the Archive to process.
13
+ :return:
14
+ """
15
+ resp = requests.get(f"{self.server}/api/archives/{id}/metadata", params={'key': self.key},
16
+ headers=self.build_headers())
17
+ return JsonUtils.to_obj(resp.text, Archive)
18
+
19
+ def get_all_archives(self) -> list[Archive]:
20
+ resp = requests.get(f"{self.server}/api/archives", params={'key': self.key}, headers=self.build_headers())
21
+ list = JsonUtils.to_obj(resp.text)
22
+ return [JsonUtils.to_obj(JsonUtils.to_str(o), Archive) for o in list]
23
+
24
+ def get_archive_categories(self, id: str) -> list[Category]:
25
+ """
26
+ Get all the Categories which currently refer to this Archive ID.
27
+ :param id: ID of the Archive to process.
28
+ :return:
29
+ """
30
+ resp = requests.get(f"{self.server}/api/archives/{id}/categories", params={'key': self.key},
31
+ headers=self.build_headers())
32
+ clist = JsonUtils.to_obj(resp.text)["categories"]
33
+ return [JsonUtils.to_obj(JsonUtils.to_str(c), Category) for c in clist]
34
+
35
+ def update_archive_metadata(self, id: str, archive: Archive) -> bool:
36
+ """
37
+ Update tags and title for the given Archive. Data supplied to the server through
38
+ this method will <b>overwrite</b> the previous data.
39
+ :param archive: the Archive whose tags and title will be updated
40
+ :param id: ID of the Archive to process.
41
+ :return: whether update succeeds
42
+ """
43
+ resp = requests.put(f"{self.server}/api/archives/{id}/metadata", params={
44
+ 'key': self.key,
45
+ 'title': archive.title,
46
+ 'tags': archive.tags
47
+ }, headers=self.build_headers())
48
+ return resp.status_code == 200
@@ -0,0 +1,5 @@
1
+ from ..common.base import BaseAPICall
2
+
3
+
4
+ class CategoryAPI(BaseAPICall):
5
+ pass
@@ -0,0 +1,5 @@
1
+ from ..common.base import BaseAPICall
2
+
3
+
4
+ class DatabaseAPI(BaseAPICall):
5
+ pass
@@ -0,0 +1,5 @@
1
+ from ..common.base import BaseAPICall
2
+
3
+
4
+ class MinionAPI(BaseAPICall):
5
+ pass
@@ -0,0 +1,5 @@
1
+ from ..common.base import BaseAPICall
2
+
3
+
4
+ class OtherAPI(BaseAPICall):
5
+ pass
@@ -0,0 +1,5 @@
1
+ from ..common.base import BaseAPICall
2
+
3
+
4
+ class SearchAPI(BaseAPICall):
5
+ pass
@@ -0,0 +1,5 @@
1
+ from ..common.base import BaseAPICall
2
+
3
+
4
+ class ShinobuAPI(BaseAPICall):
5
+ pass
File without changes
@@ -0,0 +1,25 @@
1
+ from enum import Enum
2
+
3
+
4
+ class AUTH(str, Enum):
5
+ QUERY_PARAM = 'query param'
6
+ AUTH_HEADER = 'auth header'
7
+
8
+
9
+ class BaseAPICall:
10
+
11
+ def __init__(self, key: str, server: str, auth_way: AUTH = AUTH.QUERY_PARAM, default_headers: dict[str, str] = {}):
12
+ assert auth_way == AUTH.QUERY_PARAM, 'AUTH.AUTH_HEADER is not supported now'
13
+ self.auth_way = auth_way
14
+ self.key = key
15
+ self.server = server
16
+ if self.server.endswith('/'):
17
+ self.server = self.server[:-1]
18
+ self.default_headers = default_headers
19
+
20
+ def build_headers(self, headers: dict[str, str] = {}):
21
+ for k in self.default_headers:
22
+ if k in headers:
23
+ continue
24
+ headers[k] = self.default_headers[k]
25
+ return headers
@@ -0,0 +1,72 @@
1
+
2
+ from pydantic import BaseModel
3
+
4
+
5
+ class Archive(BaseModel):
6
+ arcid: str
7
+ isnew: str
8
+ extension: str
9
+ pagecount: int
10
+ progress: int
11
+ # k1:v1, k2:v2, v3, v4
12
+ tags: str
13
+ lastreadtime: int
14
+ title: str
15
+
16
+ def tags_to_dict(self) -> dict[str, list[str]]:
17
+ tags = self.tags.split(',')
18
+ ans = {}
19
+ for t in tags:
20
+ if t == '':
21
+ continue
22
+ t = t.strip()
23
+ if ':' in t:
24
+ kv = t.split(':')
25
+ k = kv[0]
26
+ v = kv[1]
27
+ if k not in ans:
28
+ ans[k] = []
29
+ ans[k].append(v)
30
+ else:
31
+ k = "ONLY_VALUES"
32
+ if k not in ans:
33
+ ans[k] = []
34
+ ans[k].append(t)
35
+ return ans
36
+
37
+ def dict_to_tags(self, json: dict[str, list[str]]):
38
+ """
39
+ The function will modify the object
40
+ """
41
+ tags = ""
42
+ modified: bool = False
43
+ for k in json:
44
+ for v in json[k]:
45
+ modified = True
46
+ if k == 'ONLY_VALUES':
47
+ tags += f"{v},"
48
+ else:
49
+ tags += f"{k}:{v},"
50
+ if modified:
51
+ tags = tags[:-1]
52
+ self.tags = tags
53
+
54
+ def set_artists(self, artists: list[str]):
55
+ json = self.tags_to_dict()
56
+ json['artist'] = artists
57
+ self.dict_to_tags(json)
58
+
59
+ def has_artists(self) -> bool:
60
+ return "artist" in self.tags
61
+
62
+
63
+ class Category(BaseModel):
64
+ archives: list[str]
65
+ id: str
66
+ last_used: str
67
+ name: str
68
+ pinned: str
69
+ search: str
70
+
71
+
72
+
@@ -0,0 +1,13 @@
1
+ from .api import *
2
+ from .common.base import AUTH
3
+
4
+
5
+ class LANrargiAPI:
6
+ def __init__(self, key: str, server: str, auth_way: AUTH = AUTH.QUERY_PARAM, default_headers: dict[str, str] = {}):
7
+ self.archive = ArchiveAPI(key, server, auth_way=auth_way, default_headers=default_headers)
8
+ self.category = CategoryAPI(key, server, auth_way=auth_way, default_headers=default_headers)
9
+ self.database = DatabaseAPI(key, server, auth_way=auth_way, default_headers=default_headers)
10
+ self.minion = MinionAPI(key, server, auth_way=auth_way, default_headers=default_headers)
11
+ self.other = OtherAPI(key, server, auth_way=auth_way, default_headers=default_headers)
12
+ self.search = SearchAPI(key, server, auth_way=auth_way, default_headers=default_headers)
13
+ self.shinobu = ShinobuAPI(key, server, auth_way=auth_way, default_headers=default_headers)
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.1
2
+ Name: lanraragi-api
3
+ Version: 0.0.1
4
+ Summary: a Python library for LANraragi API
5
+ Home-page: https://github.com/el-nino2020/lanraragi-api
6
+ Author: El nino
7
+ Author-email: el-nino202020@protonmail.com
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: script-house
10
+
11
+ # lanraragi-api
12
+
13
+ a Python library for [LANraragi](https://github.com/Difegue/LANraragi) API.
14
+
15
+ > Many thanks to the author of this wonderful manga server app.
16
+
17
+ All the APIs are from [the official LANraragi document](https://sugoi.gitbook.io/lanraragi/api-documentation/getting-started).
18
+
19
+ Besides those basic APIs, I also made some enhancements for better use, e.g. [`lanraragi_api.common.entity.Archive#set_artists(self, artists: list[str])`](./lanraragi_api/common/entity.py)
20
+
21
+ # Demo
22
+
23
+ ```python
24
+ from lanraragi_api import LANrargiAPI
25
+ from lanraragi_api.common.entity import Archive
26
+
27
+ lgg_apikey = ''
28
+ lgg_server = 'http://127.0.0.1:3000'
29
+ api = LANrargiAPI(lgg_apikey, lgg_server)
30
+
31
+ archives: list[Archive] = api.archive.get_all_archives()
32
+ print(archives[0])
33
+ ```
34
+
35
+ # Build
36
+ ```shell
37
+ python.exe .\setup.py bdist_wheel sdist
38
+ ```
@@ -0,0 +1,17 @@
1
+ lanraragi_api/__init__.py,sha256=Ja69i2AOG6rC5Lc_tlL1K56oKw9O2lbcD1PrV4w0djo,34
2
+ lanraragi_api/lanraragi.py,sha256=e8hbNWPUeBpud3l6LcA5w1B-H1-41pvCddaKU6ANY9Q,892
3
+ lanraragi_api/api/__init__.py,sha256=r-kIIk1u9ohq4H4W1RAreR7BVGUowB5chd8DksvlvcE,227
4
+ lanraragi_api/api/archive.py,sha256=0akp-Tzf0qrMMXGXrwtJAYTpL45W9x9wCAshPds4KLQ,2118
5
+ lanraragi_api/api/category.py,sha256=81uoxveS3-q8Qn0VSNqN7K3YBawusQj1mIoc4axX-rc,86
6
+ lanraragi_api/api/database.py,sha256=vzXzRyYH-FCHswNRnkTZPtz7vvnxqju8cmpocp1Bk1o,86
7
+ lanraragi_api/api/minion.py,sha256=aXxNi4iZnQ8qPmERb014f7lHSZMBS5DLg6guaVfoQ-0,84
8
+ lanraragi_api/api/other.py,sha256=sIcRCIcfFDyOwq6hXsXw2O7piR4m2XlkdIMtMNQFxFg,83
9
+ lanraragi_api/api/search.py,sha256=C3TQ52w_AYg05JNxvO-gdYw7aztTcJ84DtublYv-ryw,84
10
+ lanraragi_api/api/shinobu.py,sha256=8VQ6Brcy7aLdF06dDN_6NCetYYheqzfvHiaTKRcOPzk,85
11
+ lanraragi_api/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ lanraragi_api/common/base.py,sha256=eFlKb-dAK9Hlo0YVy-_hmjw1tdAur_jf9FZFMfaKrc4,801
13
+ lanraragi_api/common/entity.py,sha256=S-jX91XDmdoqrv8LBg9VfE0WAix0hCQG8_LuwOM4h1A,1703
14
+ lanraragi_api-0.0.1.dist-info/METADATA,sha256=4XwqxviSllU0AZ1OWES8ixJ8W42o7R3VxAoVUXXd-N4,1144
15
+ lanraragi_api-0.0.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
16
+ lanraragi_api-0.0.1.dist-info/top_level.txt,sha256=fedIf5V5Qp9ajuI0dkjWTCwK7Kb46Xiww4CP1kTXouM,14
17
+ lanraragi_api-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.41.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ lanraragi_api