metaso-sdk 0.1.4__py3-none-any.whl → 0.1.5__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.
- metaso_sdk/__init__.py +4 -1
- metaso_sdk/bookshelf.py +22 -0
- metaso_sdk/model.py +13 -0
- metaso_sdk/subject.py +16 -14
- {metaso_sdk-0.1.4.dist-info → metaso_sdk-0.1.5.dist-info}/METADATA +1 -1
- metaso_sdk-0.1.5.dist-info/RECORD +15 -0
- metaso_sdk-0.1.4.dist-info/RECORD +0 -14
- {metaso_sdk-0.1.4.dist-info → metaso_sdk-0.1.5.dist-info}/WHEEL +0 -0
- {metaso_sdk-0.1.4.dist-info → metaso_sdk-0.1.5.dist-info}/entry_points.txt +0 -0
- {metaso_sdk-0.1.4.dist-info → metaso_sdk-0.1.5.dist-info}/licenses/LICENSE +0 -0
metaso_sdk/__init__.py
CHANGED
@@ -5,19 +5,22 @@ The official Python SDK for https://metaso.cn
|
|
5
5
|
|
6
6
|
from __future__ import annotations
|
7
7
|
|
8
|
-
from .model import File, Query, Status, Topic
|
8
|
+
from .model import File, Book, Query, Status, Topic
|
9
9
|
from .search import search
|
10
10
|
from .subject import create_topic, delete_file, delete_topic, update_progress, upload_directory, upload_file
|
11
|
+
from .bookshelf import upload_book
|
11
12
|
|
12
13
|
__all__: list[str] = [
|
13
14
|
"Status",
|
14
15
|
"Query",
|
15
16
|
"Topic",
|
16
17
|
"File",
|
18
|
+
"Book",
|
17
19
|
"search",
|
18
20
|
"create_topic",
|
19
21
|
"delete_topic",
|
20
22
|
"upload_file",
|
23
|
+
"upload_book",
|
21
24
|
"update_progress",
|
22
25
|
"delete_file",
|
23
26
|
"upload_directory",
|
metaso_sdk/bookshelf.py
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
3
|
+
from .client import client
|
4
|
+
from .model import Status, Book
|
5
|
+
|
6
|
+
|
7
|
+
def upload_book(fileobj_or_url) -> Optional[Book]:
|
8
|
+
"""上传文件或 URL 到书架。
|
9
|
+
|
10
|
+
:param fileobj_or_url: 待上传的文件对象或则 URL。
|
11
|
+
:return: 如果文件上传成功,返回 Book 对象;否则返回 None。
|
12
|
+
"""
|
13
|
+
if isinstance(fileobj_or_url, str):
|
14
|
+
params = {"data": {"url": fileobj_or_url}}
|
15
|
+
else:
|
16
|
+
params = {"files": {"file": fileobj_or_url}}
|
17
|
+
resp = client.put("/book", **params)
|
18
|
+
json = resp.json()
|
19
|
+
status = Status.model_validate(json)
|
20
|
+
if status.errCode == 0:
|
21
|
+
book = Book.model_validate(json["data"])
|
22
|
+
return book
|
metaso_sdk/model.py
CHANGED
@@ -35,3 +35,16 @@ class File(BaseModel):
|
|
35
35
|
previewUrl: Optional[str] = None
|
36
36
|
originalUrl: Optional[str] = None
|
37
37
|
progress: int
|
38
|
+
|
39
|
+
|
40
|
+
class Book(BaseModel):
|
41
|
+
id: Optional[str]
|
42
|
+
thumbImg: Optional[str]
|
43
|
+
hasPpt: bool
|
44
|
+
title: str
|
45
|
+
url: str
|
46
|
+
fileId: str
|
47
|
+
lastPage: int
|
48
|
+
totalPage: int
|
49
|
+
progress: int
|
50
|
+
size: int
|
metaso_sdk/subject.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
from pathlib import Path
|
2
|
-
from typing import List, Optional
|
2
|
+
from typing import List, Optional, Union
|
3
3
|
|
4
4
|
from streamable import Stream
|
5
5
|
|
6
6
|
from .client import client
|
7
|
-
from .model import File, Status, Topic
|
7
|
+
from .model import File, Book, Status, Topic
|
8
8
|
|
9
9
|
|
10
10
|
def create_topic(topic: Topic) -> Optional[Topic]:
|
@@ -47,27 +47,29 @@ def upload_file(topic: Topic, file) -> Optional[File]:
|
|
47
47
|
return file
|
48
48
|
|
49
49
|
|
50
|
-
def update_progress(
|
51
|
-
"""
|
50
|
+
def update_progress(file_or_book: Union[File, Book]) -> Union[File, Book]:
|
51
|
+
"""更新处理进度。
|
52
52
|
|
53
|
-
:param
|
54
|
-
:return:
|
53
|
+
:param file_or_book: 待更新进度的 File 或者 Book 对象。
|
54
|
+
:return: 更新 progress 后的对象。
|
55
55
|
"""
|
56
|
-
|
56
|
+
file_id = file_or_book.id if isinstance(file_or_book, File) else file_or_book.fileId
|
57
|
+
resp = client.get(f"/file/{file_id}/progress")
|
57
58
|
json = resp.json()
|
58
59
|
status = Status.model_validate(json)
|
59
60
|
if status.errCode == 0:
|
60
|
-
|
61
|
-
return
|
61
|
+
file_or_book.progress = json["data"]
|
62
|
+
return file_or_book
|
62
63
|
|
63
64
|
|
64
|
-
def delete_file(
|
65
|
-
"""
|
65
|
+
def delete_file(file_or_book: Union[File, Book]) -> bool:
|
66
|
+
"""删除文件。
|
66
67
|
|
67
|
-
:param
|
68
|
-
:return:
|
68
|
+
:param file_or_book: 待删除的 File 或者 Book 对象。
|
69
|
+
:return: 如果删除成功,返回True。否则返回False。
|
69
70
|
"""
|
70
|
-
|
71
|
+
file_id = file_or_book.id if isinstance(file_or_book, File) else file_or_book.fileId
|
72
|
+
resp = client.post("/file/trash", json={"ids": [file_id]})
|
71
73
|
status = Status.model_validate(resp.json())
|
72
74
|
return status.errCode == 0
|
73
75
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
metaso_sdk-0.1.5.dist-info/METADATA,sha256=6BF-8neJSO5jWgGmGlB4qj4ZjzXaAaFyecqsit-p734,3270
|
2
|
+
metaso_sdk-0.1.5.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
+
metaso_sdk-0.1.5.dist-info/entry_points.txt,sha256=VqvzYeWOYZKCpogIumetYL8h5UZsI93oLI15kJjbwj4,63
|
4
|
+
metaso_sdk-0.1.5.dist-info/licenses/LICENSE,sha256=7nWd1jm_pniRaOJtzgZnzECn_eeGLoPMvPTjCyRpj1A,1065
|
5
|
+
metaso_sdk/__init__.py,sha256=ZXHdIXVXKtjC1QgE6v7AYBXAkOgzOivIzwcVRCEvvvM,582
|
6
|
+
metaso_sdk/__main__.py,sha256=WCRS7Ehbf26-NWDSnt-Zmy0eP63paf67q9eYV4V_Q3g,345
|
7
|
+
metaso_sdk/bookshelf.py,sha256=_PtTZ54tjfjWzCkzPifWhyGRwEUFOGDGIR3acnix9a8,693
|
8
|
+
metaso_sdk/cli.py,sha256=Z7I54ojBpWxQ_Pce7-XM7gucneDIpC21yAqRGkYrm9I,1734
|
9
|
+
metaso_sdk/client.py,sha256=j2hC1NBbxsRFHC4hOSD06YrfV5JLffgrA-H5iGNBPq4,204
|
10
|
+
metaso_sdk/debug.py,sha256=K3ypLgs78a8bhiAHE_5fZZAL-U622fuKPyEdL7M1UW8,2831
|
11
|
+
metaso_sdk/model.py,sha256=_2cSadnrM-YV03e67f8wlLoAbMF3jfIsMvgNqDA5zzg,935
|
12
|
+
metaso_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
+
metaso_sdk/search.py,sha256=3iA9lIncpAcbPHPby0XnTYaYvhM2983bEOBa40Nu_kY,1082
|
14
|
+
metaso_sdk/subject.py,sha256=FfiFOoNqunQd4nHG84zYGWJd10xZeljL5iQiFC8UshY,3255
|
15
|
+
metaso_sdk-0.1.5.dist-info/RECORD,,
|
@@ -1,14 +0,0 @@
|
|
1
|
-
metaso_sdk-0.1.4.dist-info/METADATA,sha256=Ci3lD-LlXIN7M48tAwsDkqfBqq-p96JzfzR47YYTFu8,3270
|
2
|
-
metaso_sdk-0.1.4.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
-
metaso_sdk-0.1.4.dist-info/entry_points.txt,sha256=VqvzYeWOYZKCpogIumetYL8h5UZsI93oLI15kJjbwj4,63
|
4
|
-
metaso_sdk-0.1.4.dist-info/licenses/LICENSE,sha256=7nWd1jm_pniRaOJtzgZnzECn_eeGLoPMvPTjCyRpj1A,1065
|
5
|
-
metaso_sdk/__init__.py,sha256=wP088gdhNJt1byFsSYest-ucQJdwosorwaG7FqCyqwE,510
|
6
|
-
metaso_sdk/__main__.py,sha256=WCRS7Ehbf26-NWDSnt-Zmy0eP63paf67q9eYV4V_Q3g,345
|
7
|
-
metaso_sdk/cli.py,sha256=Z7I54ojBpWxQ_Pce7-XM7gucneDIpC21yAqRGkYrm9I,1734
|
8
|
-
metaso_sdk/client.py,sha256=j2hC1NBbxsRFHC4hOSD06YrfV5JLffgrA-H5iGNBPq4,204
|
9
|
-
metaso_sdk/debug.py,sha256=K3ypLgs78a8bhiAHE_5fZZAL-U622fuKPyEdL7M1UW8,2831
|
10
|
-
metaso_sdk/model.py,sha256=Y-8Gn_9K4lbtqhiGVs796hB3UXMfgUALAFOjwJXiwDQ,730
|
11
|
-
metaso_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
metaso_sdk/search.py,sha256=3iA9lIncpAcbPHPby0XnTYaYvhM2983bEOBa40Nu_kY,1082
|
13
|
-
metaso_sdk/subject.py,sha256=qJBSn5LimFJ1df4sEWnp4or1rQlAGq-nWdPjac_heq4,2966
|
14
|
-
metaso_sdk-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|