chunkr-ai 0.0.35__py3-none-any.whl → 0.0.36__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.
- chunkr_ai/api/task_response.py +27 -22
- {chunkr_ai-0.0.35.dist-info → chunkr_ai-0.0.36.dist-info}/METADATA +1 -1
- {chunkr_ai-0.0.35.dist-info → chunkr_ai-0.0.36.dist-info}/RECORD +6 -6
- {chunkr_ai-0.0.35.dist-info → chunkr_ai-0.0.36.dist-info}/LICENSE +0 -0
- {chunkr_ai-0.0.35.dist-info → chunkr_ai-0.0.36.dist-info}/WHEEL +0 -0
- {chunkr_ai-0.0.35.dist-info → chunkr_ai-0.0.36.dist-info}/top_level.txt +0 -0
chunkr_ai/api/task_response.py
CHANGED
@@ -103,6 +103,29 @@ class TaskResponse(BaseModel, Generic[T]):
|
|
103
103
|
r.raise_for_status()
|
104
104
|
return await self.poll()
|
105
105
|
|
106
|
+
def _write_to_file(self, content: str | dict, output_file: str, is_json: bool = False) -> None:
|
107
|
+
"""Helper method to write content to a file
|
108
|
+
|
109
|
+
Args:
|
110
|
+
content: Content to write (string or dict for JSON)
|
111
|
+
output_file: Path to save the content
|
112
|
+
is_json: Whether the content should be written as JSON
|
113
|
+
"""
|
114
|
+
class DateTimeEncoder(json.JSONEncoder):
|
115
|
+
def default(self, obj):
|
116
|
+
if isinstance(obj, datetime):
|
117
|
+
return obj.isoformat()
|
118
|
+
return super().default(obj)
|
119
|
+
if output_file:
|
120
|
+
directory = os.path.dirname(output_file)
|
121
|
+
if directory:
|
122
|
+
os.makedirs(directory, exist_ok=True)
|
123
|
+
with open(output_file, "w", encoding="utf-8") as f:
|
124
|
+
if is_json:
|
125
|
+
json.dump(content, f, cls=DateTimeEncoder, indent=2)
|
126
|
+
else:
|
127
|
+
f.write(content)
|
128
|
+
|
106
129
|
def html(self, output_file: str = None) -> str:
|
107
130
|
"""Get the full HTML of the task
|
108
131
|
|
@@ -110,10 +133,7 @@ class TaskResponse(BaseModel, Generic[T]):
|
|
110
133
|
output_file (str, optional): Path to save the HTML content. Defaults to None.
|
111
134
|
"""
|
112
135
|
content = self._get_content("html")
|
113
|
-
|
114
|
-
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
115
|
-
with open(output_file, "w", encoding="utf-8") as f:
|
116
|
-
f.write(content)
|
136
|
+
self._write_to_file(content, output_file)
|
117
137
|
return content
|
118
138
|
|
119
139
|
def markdown(self, output_file: str = None) -> str:
|
@@ -123,10 +143,7 @@ class TaskResponse(BaseModel, Generic[T]):
|
|
123
143
|
output_file (str, optional): Path to save the markdown content. Defaults to None.
|
124
144
|
"""
|
125
145
|
content = self._get_content("markdown")
|
126
|
-
|
127
|
-
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
128
|
-
with open(output_file, "w", encoding="utf-8") as f:
|
129
|
-
f.write(content)
|
146
|
+
self._write_to_file(content, output_file)
|
130
147
|
return content
|
131
148
|
|
132
149
|
def content(self, output_file: str = None) -> str:
|
@@ -136,10 +153,7 @@ class TaskResponse(BaseModel, Generic[T]):
|
|
136
153
|
output_file (str, optional): Path to save the content. Defaults to None.
|
137
154
|
"""
|
138
155
|
content = self._get_content("content")
|
139
|
-
|
140
|
-
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
141
|
-
with open(output_file, "w", encoding="utf-8") as f:
|
142
|
-
f.write(content)
|
156
|
+
self._write_to_file(content, output_file)
|
143
157
|
return content
|
144
158
|
|
145
159
|
def json(self, output_file: str = None) -> dict:
|
@@ -148,17 +162,8 @@ class TaskResponse(BaseModel, Generic[T]):
|
|
148
162
|
Args:
|
149
163
|
output_file (str, optional): Path to save the task data as JSON. Defaults to None.
|
150
164
|
"""
|
151
|
-
class DateTimeEncoder(json.JSONEncoder):
|
152
|
-
def default(self, obj):
|
153
|
-
if isinstance(obj, datetime):
|
154
|
-
return obj.isoformat()
|
155
|
-
return super().default(obj)
|
156
|
-
|
157
165
|
data = self.model_dump()
|
158
|
-
|
159
|
-
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
160
|
-
with open(output_file, "w", encoding="utf-8") as f:
|
161
|
-
json.dump(data, f, cls=DateTimeEncoder, indent=2)
|
166
|
+
self._write_to_file(data, output_file, is_json=True)
|
162
167
|
return data
|
163
168
|
|
164
169
|
def _get_content(self, t: str) -> str:
|
@@ -8,9 +8,9 @@ chunkr_ai/api/configuration.py,sha256=2Bfw_c8eQVijb0EvsexiuRbF1pZUspYFBMuZ-ErJHv
|
|
8
8
|
chunkr_ai/api/decorators.py,sha256=VJX4qGBIL00K2zY8bh5KAMWv7SltJ38TvPJH06FnFss,4415
|
9
9
|
chunkr_ai/api/misc.py,sha256=gTL8UG_R6bunQdKSXwm_SpyIyTmLprzdX3re_X-mMto,5730
|
10
10
|
chunkr_ai/api/protocol.py,sha256=LjPrYSq52m1afIlAo0yVGXlGZxPRh8J6g7S4PAit3Zo,388
|
11
|
-
chunkr_ai/api/task_response.py,sha256=
|
12
|
-
chunkr_ai-0.0.
|
13
|
-
chunkr_ai-0.0.
|
14
|
-
chunkr_ai-0.0.
|
15
|
-
chunkr_ai-0.0.
|
16
|
-
chunkr_ai-0.0.
|
11
|
+
chunkr_ai/api/task_response.py,sha256=FC4OQUv4fltUij5OtFRlWRE9LxzRJGgBhh0olfHJBBg,6258
|
12
|
+
chunkr_ai-0.0.36.dist-info/LICENSE,sha256=w3R12yNDyZpMiy2lxy_hvNbsldC75ww79sF0u11rkho,1069
|
13
|
+
chunkr_ai-0.0.36.dist-info/METADATA,sha256=1hamwWrDvj0DirX84MAAbZs_yqSxmzGVR7mK7521HK0,7031
|
14
|
+
chunkr_ai-0.0.36.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
15
|
+
chunkr_ai-0.0.36.dist-info/top_level.txt,sha256=0IZY7PZIiS8bw5r4NUQRUQ-ATi-L_3vLQVq3ZLouOW8,10
|
16
|
+
chunkr_ai-0.0.36.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|