moltcli 0.1.0__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.
- moltcli/__init__.py +3 -0
- moltcli/cli.py +376 -0
- moltcli/core/__init__.py +19 -0
- moltcli/core/auth.py +21 -0
- moltcli/core/comment.py +36 -0
- moltcli/core/feed.py +30 -0
- moltcli/core/post.py +41 -0
- moltcli/core/search.py +29 -0
- moltcli/core/submolts.py +34 -0
- moltcli/core/vote.py +30 -0
- moltcli/utils/__init__.py +25 -0
- moltcli/utils/api_client.py +87 -0
- moltcli/utils/config.py +57 -0
- moltcli/utils/errors.py +145 -0
- moltcli/utils/formatter.py +40 -0
- moltcli-0.1.0.dist-info/METADATA +116 -0
- moltcli-0.1.0.dist-info/RECORD +21 -0
- moltcli-0.1.0.dist-info/WHEEL +5 -0
- moltcli-0.1.0.dist-info/entry_points.txt +2 -0
- moltcli-0.1.0.dist-info/licenses/LICENSE +21 -0
- moltcli-0.1.0.dist-info/top_level.txt +1 -0
moltcli/__init__.py
ADDED
moltcli/cli.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"""MoltCLI - CLI tool for Moltbook social network."""
|
|
2
|
+
import sys
|
|
3
|
+
import click
|
|
4
|
+
from .utils import get_config, MoltbookClient, OutputFormatter, handle_error
|
|
5
|
+
from .core import (
|
|
6
|
+
PostCore,
|
|
7
|
+
CommentCore,
|
|
8
|
+
FeedCore,
|
|
9
|
+
SearchCore,
|
|
10
|
+
VoteCore,
|
|
11
|
+
SubmoltsCore,
|
|
12
|
+
AuthCore,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_client() -> MoltbookClient:
|
|
17
|
+
"""Create API client from config."""
|
|
18
|
+
config = get_config()
|
|
19
|
+
return MoltbookClient(config.api_key)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def make_formatter(json_mode: bool) -> OutputFormatter:
|
|
23
|
+
"""Create output formatter."""
|
|
24
|
+
return OutputFormatter(json_mode=json_mode)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Global options
|
|
28
|
+
@click.group()
|
|
29
|
+
@click.option("--json", "json_mode", is_flag=True, help="Output as JSON")
|
|
30
|
+
@click.pass_context
|
|
31
|
+
def cli(ctx: click.Context, json_mode: bool):
|
|
32
|
+
"""MoltCLI - CLI tool for Moltbook social network."""
|
|
33
|
+
ctx.ensure_object(dict)
|
|
34
|
+
ctx.obj["json_mode"] = json_mode
|
|
35
|
+
ctx.obj["formatter"] = make_formatter(json_mode)
|
|
36
|
+
ctx.obj["client"] = get_client()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# auth command group
|
|
40
|
+
@cli.group()
|
|
41
|
+
def auth():
|
|
42
|
+
"""Authentication management."""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@auth.command("whoami")
|
|
47
|
+
@click.pass_context
|
|
48
|
+
def auth_whoami(ctx: click.Context):
|
|
49
|
+
"""Show current user info."""
|
|
50
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
51
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
52
|
+
try:
|
|
53
|
+
result = AuthCore(client).whoami()
|
|
54
|
+
formatter.print(result)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
if ctx.obj["json_mode"]:
|
|
57
|
+
formatter.print(handle_error(e))
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
raise
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@auth.command("verify")
|
|
63
|
+
@click.pass_context
|
|
64
|
+
def auth_verify(ctx: click.Context):
|
|
65
|
+
"""Verify API key is valid."""
|
|
66
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
67
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
68
|
+
try:
|
|
69
|
+
result = AuthCore(client).verify()
|
|
70
|
+
formatter.print({"status": "valid", "message": "API key is valid"})
|
|
71
|
+
except Exception as e:
|
|
72
|
+
if ctx.obj["json_mode"]:
|
|
73
|
+
formatter.print(handle_error(e))
|
|
74
|
+
sys.exit(1)
|
|
75
|
+
raise
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# post command group
|
|
79
|
+
@cli.group()
|
|
80
|
+
def post():
|
|
81
|
+
"""Post operations."""
|
|
82
|
+
pass
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@post.command("create")
|
|
86
|
+
@click.option("--submolt", required=True, help="Submolt name")
|
|
87
|
+
@click.option("--title", required=True, help="Post title")
|
|
88
|
+
@click.option("--content", help="Post content")
|
|
89
|
+
@click.option("--url", help="Post URL")
|
|
90
|
+
@click.pass_context
|
|
91
|
+
def post_create(ctx: click.Context, submolt: str, title: str, content: str, url: str):
|
|
92
|
+
"""Create a new post."""
|
|
93
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
94
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
95
|
+
try:
|
|
96
|
+
result = PostCore(client).create(submolt=submolt, title=title, content=content, url=url)
|
|
97
|
+
formatter.print(result)
|
|
98
|
+
except Exception as e:
|
|
99
|
+
if ctx.obj["json_mode"]:
|
|
100
|
+
formatter.print(handle_error(e))
|
|
101
|
+
sys.exit(1)
|
|
102
|
+
raise
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@post.command("get")
|
|
106
|
+
@click.argument("post_id")
|
|
107
|
+
@click.pass_context
|
|
108
|
+
def post_get(ctx: click.Context, post_id: str):
|
|
109
|
+
"""Get a post by ID."""
|
|
110
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
111
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
112
|
+
try:
|
|
113
|
+
result = PostCore(client).get(post_id)
|
|
114
|
+
formatter.print(result)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
if ctx.obj["json_mode"]:
|
|
117
|
+
formatter.print(handle_error(e))
|
|
118
|
+
sys.exit(1)
|
|
119
|
+
raise
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@post.command("delete")
|
|
123
|
+
@click.argument("post_id")
|
|
124
|
+
@click.pass_context
|
|
125
|
+
def post_delete(ctx: click.Context, post_id: str):
|
|
126
|
+
"""Delete a post."""
|
|
127
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
128
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
129
|
+
try:
|
|
130
|
+
result = PostCore(client).delete(post_id)
|
|
131
|
+
formatter.print({"status": "deleted", "id": post_id})
|
|
132
|
+
except Exception as e:
|
|
133
|
+
if ctx.obj["json_mode"]:
|
|
134
|
+
formatter.print(handle_error(e))
|
|
135
|
+
sys.exit(1)
|
|
136
|
+
raise
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# comment command group
|
|
140
|
+
@cli.group()
|
|
141
|
+
def comment():
|
|
142
|
+
"""Comment operations."""
|
|
143
|
+
pass
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@comment.command("create")
|
|
147
|
+
@click.argument("post_id")
|
|
148
|
+
@click.option("--content", required=True, help="Comment content")
|
|
149
|
+
@click.option("--parent", help="Parent comment ID for replies")
|
|
150
|
+
@click.pass_context
|
|
151
|
+
def comment_create(ctx: click.Context, post_id: str, content: str, parent: str):
|
|
152
|
+
"""Create a comment on a post."""
|
|
153
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
154
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
155
|
+
try:
|
|
156
|
+
result = CommentCore(client).create(post_id=post_id, content=content, parent_id=parent)
|
|
157
|
+
formatter.print(result)
|
|
158
|
+
except Exception as e:
|
|
159
|
+
if ctx.obj["json_mode"]:
|
|
160
|
+
formatter.print(handle_error(e))
|
|
161
|
+
sys.exit(1)
|
|
162
|
+
raise
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@comment.command("list")
|
|
166
|
+
@click.argument("post_id")
|
|
167
|
+
@click.option("--limit", default=50, help="Max comments to show")
|
|
168
|
+
@click.pass_context
|
|
169
|
+
def comment_list(ctx: click.Context, post_id: str, limit: int):
|
|
170
|
+
"""List comments for a post."""
|
|
171
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
172
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
173
|
+
try:
|
|
174
|
+
result = CommentCore(client).list_by_post(post_id, limit=limit)
|
|
175
|
+
formatter.print(result)
|
|
176
|
+
except Exception as e:
|
|
177
|
+
if ctx.obj["json_mode"]:
|
|
178
|
+
formatter.print(handle_error(e))
|
|
179
|
+
sys.exit(1)
|
|
180
|
+
raise
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
# feed command group
|
|
184
|
+
@cli.group()
|
|
185
|
+
def feed():
|
|
186
|
+
"""Feed operations."""
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@feed.command()
|
|
191
|
+
@click.option("--sort", type=click.Choice(["hot", "new"]), default="hot", help="Sort order")
|
|
192
|
+
@click.option("--limit", default=20, help="Max posts to show")
|
|
193
|
+
@click.option("--submolt", help="Filter by submolt")
|
|
194
|
+
@click.pass_context
|
|
195
|
+
def feed_get(ctx: click.Context, sort: str, limit: int, submolt: str):
|
|
196
|
+
"""Get feed posts."""
|
|
197
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
198
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
199
|
+
try:
|
|
200
|
+
result = FeedCore(client).get(sort=sort, limit=limit, submolt=submolt)
|
|
201
|
+
formatter.print(result)
|
|
202
|
+
except Exception as e:
|
|
203
|
+
if ctx.obj["json_mode"]:
|
|
204
|
+
formatter.print(handle_error(e))
|
|
205
|
+
sys.exit(1)
|
|
206
|
+
raise
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@feed.command("hot")
|
|
210
|
+
@click.option("--limit", default=20, help="Max posts to show")
|
|
211
|
+
@click.pass_context
|
|
212
|
+
def feed_hot(ctx: click.Context, limit: int):
|
|
213
|
+
"""Get hot posts."""
|
|
214
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
215
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
216
|
+
try:
|
|
217
|
+
result = FeedCore(client).get_hot(limit=limit)
|
|
218
|
+
formatter.print(result)
|
|
219
|
+
except Exception as e:
|
|
220
|
+
if ctx.obj["json_mode"]:
|
|
221
|
+
formatter.print(handle_error(e))
|
|
222
|
+
sys.exit(1)
|
|
223
|
+
raise
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@feed.command("new")
|
|
227
|
+
@click.option("--limit", default=20, help="Max posts to show")
|
|
228
|
+
@click.pass_context
|
|
229
|
+
def feed_new(ctx: click.Context, limit: int):
|
|
230
|
+
"""Get newest posts."""
|
|
231
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
232
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
233
|
+
try:
|
|
234
|
+
result = FeedCore(client).get_new(limit=limit)
|
|
235
|
+
formatter.print(result)
|
|
236
|
+
except Exception as e:
|
|
237
|
+
if ctx.obj["json_mode"]:
|
|
238
|
+
formatter.print(handle_error(e))
|
|
239
|
+
sys.exit(1)
|
|
240
|
+
raise
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# search command group
|
|
244
|
+
@cli.group()
|
|
245
|
+
def search():
|
|
246
|
+
"""Search operations."""
|
|
247
|
+
pass
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@search.command()
|
|
251
|
+
@click.argument("query")
|
|
252
|
+
@click.option("--type", type=click.Choice(["posts", "users"]), default="posts", help="Search type")
|
|
253
|
+
@click.option("--limit", default=20, help="Max results")
|
|
254
|
+
@click.pass_context
|
|
255
|
+
def search_query(ctx: click.Context, query: str, type_: str, limit: int):
|
|
256
|
+
"""Search posts or users."""
|
|
257
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
258
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
259
|
+
try:
|
|
260
|
+
result = SearchCore(client).search(query=query, type_=type_, limit=limit)
|
|
261
|
+
formatter.print(result)
|
|
262
|
+
except Exception as e:
|
|
263
|
+
if ctx.obj["json_mode"]:
|
|
264
|
+
formatter.print(handle_error(e))
|
|
265
|
+
sys.exit(1)
|
|
266
|
+
raise
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
# vote command group
|
|
270
|
+
@cli.group()
|
|
271
|
+
def vote():
|
|
272
|
+
"""Vote operations."""
|
|
273
|
+
pass
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
@vote.command("up")
|
|
277
|
+
@click.argument("item_id")
|
|
278
|
+
@click.option("--type", type=click.Choice(["post", "comment"]), default="post", help="Item type")
|
|
279
|
+
@click.pass_context
|
|
280
|
+
def vote_up(ctx: click.Context, item_id: str, type_: str):
|
|
281
|
+
"""Upvote a post or comment."""
|
|
282
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
283
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
284
|
+
try:
|
|
285
|
+
result = VoteCore(client).upvote(item_id, type_=type_)
|
|
286
|
+
formatter.print({"status": "upvoted", "id": item_id})
|
|
287
|
+
except Exception as e:
|
|
288
|
+
if ctx.obj["json_mode"]:
|
|
289
|
+
formatter.print(handle_error(e))
|
|
290
|
+
sys.exit(1)
|
|
291
|
+
raise
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@vote.command("down")
|
|
295
|
+
@click.argument("item_id")
|
|
296
|
+
@click.option("--type", type=click.Choice(["post", "comment"]), default="post", help="Item type")
|
|
297
|
+
@click.pass_context
|
|
298
|
+
def vote_down(ctx: click.Context, item_id: str, type_: str):
|
|
299
|
+
"""Downvote a post or comment."""
|
|
300
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
301
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
302
|
+
try:
|
|
303
|
+
result = VoteCore(client).downvote(item_id, type_=type_)
|
|
304
|
+
formatter.print({"status": "downvoted", "id": item_id})
|
|
305
|
+
except Exception as e:
|
|
306
|
+
if ctx.obj["json_mode"]:
|
|
307
|
+
formatter.print(handle_error(e))
|
|
308
|
+
sys.exit(1)
|
|
309
|
+
raise
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
# submolts command group
|
|
313
|
+
@cli.group()
|
|
314
|
+
def submolts():
|
|
315
|
+
"""Submolt operations."""
|
|
316
|
+
pass
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
@submolts.command("list")
|
|
320
|
+
@click.option("--limit", default=50, help="Max submolts to show")
|
|
321
|
+
@click.pass_context
|
|
322
|
+
def submolts_list(ctx: click.Context, limit: int):
|
|
323
|
+
"""List all submolts."""
|
|
324
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
325
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
326
|
+
try:
|
|
327
|
+
result = SubmoltsCore(client).list(limit=limit)
|
|
328
|
+
formatter.print(result)
|
|
329
|
+
except Exception as e:
|
|
330
|
+
if ctx.obj["json_mode"]:
|
|
331
|
+
formatter.print(handle_error(e))
|
|
332
|
+
sys.exit(1)
|
|
333
|
+
raise
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
@submolts.command("subscribe")
|
|
337
|
+
@click.argument("name")
|
|
338
|
+
@click.pass_context
|
|
339
|
+
def submolts_subscribe(ctx: click.Context, name: str):
|
|
340
|
+
"""Subscribe to a submolt."""
|
|
341
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
342
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
343
|
+
try:
|
|
344
|
+
result = SubmoltsCore(client).subscribe(name)
|
|
345
|
+
formatter.print({"status": "subscribed", "name": name})
|
|
346
|
+
except Exception as e:
|
|
347
|
+
if ctx.obj["json_mode"]:
|
|
348
|
+
formatter.print(handle_error(e))
|
|
349
|
+
sys.exit(1)
|
|
350
|
+
raise
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
@submolts.command("unsubscribe")
|
|
354
|
+
@click.argument("name")
|
|
355
|
+
@click.pass_context
|
|
356
|
+
def submolts_unsubscribe(ctx: click.Context, name: str):
|
|
357
|
+
"""Unsubscribe from a submolt."""
|
|
358
|
+
client: MoltbookClient = ctx.obj["client"]
|
|
359
|
+
formatter: OutputFormatter = ctx.obj["formatter"]
|
|
360
|
+
try:
|
|
361
|
+
result = SubmoltsCore(client).unsubscribe(name)
|
|
362
|
+
formatter.print({"status": "unsubscribed", "name": name})
|
|
363
|
+
except Exception as e:
|
|
364
|
+
if ctx.obj["json_mode"]:
|
|
365
|
+
formatter.print(handle_error(e))
|
|
366
|
+
sys.exit(1)
|
|
367
|
+
raise
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def main():
|
|
371
|
+
"""Entry point."""
|
|
372
|
+
cli()
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
if __name__ == "__main__":
|
|
376
|
+
main()
|
moltcli/core/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""MoltCLI core business logic."""
|
|
2
|
+
|
|
3
|
+
from .post import PostCore
|
|
4
|
+
from .comment import CommentCore
|
|
5
|
+
from .feed import FeedCore
|
|
6
|
+
from .search import SearchCore
|
|
7
|
+
from .vote import VoteCore
|
|
8
|
+
from .submolts import SubmoltsCore
|
|
9
|
+
from .auth import AuthCore
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"PostCore",
|
|
13
|
+
"CommentCore",
|
|
14
|
+
"FeedCore",
|
|
15
|
+
"SearchCore",
|
|
16
|
+
"VoteCore",
|
|
17
|
+
"SubmoltsCore",
|
|
18
|
+
"AuthCore",
|
|
19
|
+
]
|
moltcli/core/auth.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Auth core logic."""
|
|
2
|
+
from ..utils.api_client import MoltbookClient
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AuthCore:
|
|
6
|
+
"""Handle authentication operations."""
|
|
7
|
+
|
|
8
|
+
def __init__(self, client: MoltbookClient):
|
|
9
|
+
self._client = client
|
|
10
|
+
|
|
11
|
+
def whoami(self) -> dict:
|
|
12
|
+
"""Get current user info."""
|
|
13
|
+
return self._client.get("/auth/whoami")
|
|
14
|
+
|
|
15
|
+
def verify(self) -> dict:
|
|
16
|
+
"""Verify API key is valid."""
|
|
17
|
+
return self._client.get("/auth/verify")
|
|
18
|
+
|
|
19
|
+
def refresh(self) -> dict:
|
|
20
|
+
"""Refresh authentication token."""
|
|
21
|
+
return self._client.post("/auth/refresh")
|
moltcli/core/comment.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Comment core logic."""
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from ..utils.api_client import MoltbookClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CommentCore:
|
|
7
|
+
"""Handle comment operations."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, client: MoltbookClient):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
def create(
|
|
13
|
+
self,
|
|
14
|
+
post_id: str,
|
|
15
|
+
content: str,
|
|
16
|
+
parent_id: Optional[str] = None,
|
|
17
|
+
) -> dict:
|
|
18
|
+
"""Create a comment on a post."""
|
|
19
|
+
data = {"post_id": post_id, "content": content}
|
|
20
|
+
if parent_id:
|
|
21
|
+
data["parent_id"] = parent_id
|
|
22
|
+
return self._client.post("/comments", json_data=data)
|
|
23
|
+
|
|
24
|
+
def get(self, comment_id: str) -> dict:
|
|
25
|
+
"""Get a comment by ID."""
|
|
26
|
+
return self._client.get(f"/comments/{comment_id}")
|
|
27
|
+
|
|
28
|
+
def delete(self, comment_id: str) -> dict:
|
|
29
|
+
"""Delete a comment."""
|
|
30
|
+
return self._client.delete(f"/comments/{comment_id}")
|
|
31
|
+
|
|
32
|
+
def list_by_post(self, post_id: str, limit: int = 50) -> dict:
|
|
33
|
+
"""List comments for a post."""
|
|
34
|
+
return self._client.get(
|
|
35
|
+
f"/posts/{post_id}/comments", params={"limit": limit}
|
|
36
|
+
)
|
moltcli/core/feed.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Feed core logic."""
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from ..utils.api_client import MoltbookClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class FeedCore:
|
|
7
|
+
"""Handle feed operations."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, client: MoltbookClient):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
def get(
|
|
13
|
+
self,
|
|
14
|
+
sort: str = "hot",
|
|
15
|
+
limit: int = 20,
|
|
16
|
+
submolt: Optional[str] = None,
|
|
17
|
+
) -> dict:
|
|
18
|
+
"""Get feed posts."""
|
|
19
|
+
params = {"sort": sort, "limit": limit}
|
|
20
|
+
if submolt:
|
|
21
|
+
params["submolt"] = submolt
|
|
22
|
+
return self._client.get("/feed", params=params)
|
|
23
|
+
|
|
24
|
+
def get_hot(self, limit: int = 20) -> dict:
|
|
25
|
+
"""Get hot posts."""
|
|
26
|
+
return self.get(sort="hot", limit=limit)
|
|
27
|
+
|
|
28
|
+
def get_new(self, limit: int = 20) -> dict:
|
|
29
|
+
"""Get newest posts."""
|
|
30
|
+
return self.get(sort="new", limit=limit)
|
moltcli/core/post.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Post core logic."""
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from ..utils.api_client import MoltbookClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PostCore:
|
|
7
|
+
"""Handle post operations."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, client: MoltbookClient):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
def create(
|
|
13
|
+
self,
|
|
14
|
+
submolt: str,
|
|
15
|
+
title: str,
|
|
16
|
+
content: Optional[str] = None,
|
|
17
|
+
url: Optional[str] = None,
|
|
18
|
+
) -> dict:
|
|
19
|
+
"""Create a new post."""
|
|
20
|
+
data = {"submolt": submolt, "title": title}
|
|
21
|
+
if content:
|
|
22
|
+
data["content"] = content
|
|
23
|
+
if url:
|
|
24
|
+
data["url"] = url
|
|
25
|
+
return self._client.post("/posts", json_data=data)
|
|
26
|
+
|
|
27
|
+
def get(self, post_id: str) -> dict:
|
|
28
|
+
"""Get a post by ID."""
|
|
29
|
+
return self._client.get(f"/posts/{post_id}")
|
|
30
|
+
|
|
31
|
+
def delete(self, post_id: str) -> dict:
|
|
32
|
+
"""Delete a post."""
|
|
33
|
+
return self._client.delete(f"/posts/{post_id}")
|
|
34
|
+
|
|
35
|
+
def list_by_submolt(
|
|
36
|
+
self, submolt: str, limit: int = 20, offset: int = 0
|
|
37
|
+
) -> dict:
|
|
38
|
+
"""List posts in a submolt."""
|
|
39
|
+
return self._client.get(
|
|
40
|
+
f"/submolts/{submolt}/posts", params={"limit": limit, "offset": offset}
|
|
41
|
+
)
|
moltcli/core/search.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Search core logic."""
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from ..utils.api_client import MoltbookClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SearchCore:
|
|
7
|
+
"""Handle search operations."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, client: MoltbookClient):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
def search(
|
|
13
|
+
self,
|
|
14
|
+
query: str,
|
|
15
|
+
type_: str = "posts",
|
|
16
|
+
limit: int = 20,
|
|
17
|
+
) -> dict:
|
|
18
|
+
"""Search posts and users."""
|
|
19
|
+
return self._client.get(
|
|
20
|
+
"/search", params={"q": query, "type": type_, "limit": limit}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def search_posts(self, query: str, limit: int = 20) -> dict:
|
|
24
|
+
"""Search posts only."""
|
|
25
|
+
return self.search(query, type_="posts", limit=limit)
|
|
26
|
+
|
|
27
|
+
def search_users(self, query: str, limit: int = 20) -> dict:
|
|
28
|
+
"""Search users only."""
|
|
29
|
+
return self.search(query, type_="users", limit=limit)
|
moltcli/core/submolts.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Submolts core logic."""
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from ..utils.api_client import MoltbookClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SubmoltsCore:
|
|
7
|
+
"""Handle submolt operations."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, client: MoltbookClient):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
def list(self, limit: int = 50) -> dict:
|
|
13
|
+
"""List all submolts."""
|
|
14
|
+
return self._client.get("/submolts", params={"limit": limit})
|
|
15
|
+
|
|
16
|
+
def get(self, name: str) -> dict:
|
|
17
|
+
"""Get a submolt by name."""
|
|
18
|
+
return self._client.get(f"/submolts/{name}")
|
|
19
|
+
|
|
20
|
+
def subscribe(self, name: str) -> dict:
|
|
21
|
+
"""Subscribe to a submolt."""
|
|
22
|
+
return self._client.post("/submolts/subscribe", json_data={"name": name})
|
|
23
|
+
|
|
24
|
+
def unsubscribe(self, name: str) -> dict:
|
|
25
|
+
"""Unsubscribe from a submolt."""
|
|
26
|
+
return self._client.post("/submolts/unsubscribe", json_data={"name": name})
|
|
27
|
+
|
|
28
|
+
def get_subscribed(self) -> dict:
|
|
29
|
+
"""Get user's subscribed submolts."""
|
|
30
|
+
return self._client.get("/user/subscriptions")
|
|
31
|
+
|
|
32
|
+
def trending(self, limit: int = 10) -> dict:
|
|
33
|
+
"""Get trending submolts."""
|
|
34
|
+
return self._client.get("/submolts/trending", params={"limit": limit})
|
moltcli/core/vote.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Vote core logic."""
|
|
2
|
+
from ..utils.api_client import MoltbookClient
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class VoteCore:
|
|
6
|
+
"""Handle vote operations."""
|
|
7
|
+
|
|
8
|
+
UP = "up"
|
|
9
|
+
DOWN = "down"
|
|
10
|
+
|
|
11
|
+
def __init__(self, client: MoltbookClient):
|
|
12
|
+
self._client = client
|
|
13
|
+
|
|
14
|
+
def upvote(self, item_id: str, type_: str = "post") -> dict:
|
|
15
|
+
"""Upvote a post or comment."""
|
|
16
|
+
return self._vote(item_id, self.UP, type_)
|
|
17
|
+
|
|
18
|
+
def downvote(self, item_id: str, type_: str = "post") -> dict:
|
|
19
|
+
"""Downvote a post or comment."""
|
|
20
|
+
return self._vote(item_id, self.DOWN, type_)
|
|
21
|
+
|
|
22
|
+
def _vote(self, item_id: str, direction: str, type_: str) -> dict:
|
|
23
|
+
"""Internal vote method."""
|
|
24
|
+
return self._client.post(
|
|
25
|
+
"/votes", json_data={"item_id": item_id, "type": type_, "direction": direction}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def remove_vote(self, item_id: str, type_: str = "post") -> dict:
|
|
29
|
+
"""Remove a vote."""
|
|
30
|
+
return self._client.delete(f"/votes/{item_id}?type={type_}")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""MoltCLI utils package."""
|
|
2
|
+
from .config import Config, get_config
|
|
3
|
+
from .api_client import MoltbookClient
|
|
4
|
+
from .formatter import OutputFormatter
|
|
5
|
+
from .errors import (
|
|
6
|
+
MoltCLIError,
|
|
7
|
+
AuthError,
|
|
8
|
+
NotFoundError,
|
|
9
|
+
RateLimitError,
|
|
10
|
+
handle_error,
|
|
11
|
+
parse_rate_limit_from_response,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Config",
|
|
16
|
+
"get_config",
|
|
17
|
+
"MoltbookClient",
|
|
18
|
+
"OutputFormatter",
|
|
19
|
+
"MoltCLIError",
|
|
20
|
+
"AuthError",
|
|
21
|
+
"NotFoundError",
|
|
22
|
+
"RateLimitError",
|
|
23
|
+
"handle_error",
|
|
24
|
+
"parse_rate_limit_from_response",
|
|
25
|
+
]
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Moltbook API client."""
|
|
2
|
+
import requests
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
from .errors import RateLimitError, AuthError, NotFoundError, parse_rate_limit_from_response
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MoltbookClient:
|
|
9
|
+
"""HTTP client for Moltbook API."""
|
|
10
|
+
|
|
11
|
+
BASE_URL = "https://www.moltbook.com/api/v1"
|
|
12
|
+
|
|
13
|
+
def __init__(self, api_key: str):
|
|
14
|
+
self.api_key = api_key
|
|
15
|
+
self.headers = {
|
|
16
|
+
"Authorization": f"Bearer {api_key}",
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
def _request(
|
|
21
|
+
self,
|
|
22
|
+
method: str,
|
|
23
|
+
endpoint: str,
|
|
24
|
+
*,
|
|
25
|
+
params: Optional[dict] = None,
|
|
26
|
+
json_data: Optional[dict] = None,
|
|
27
|
+
) -> dict:
|
|
28
|
+
"""Make HTTP request and handle errors."""
|
|
29
|
+
url = f"{self.BASE_URL}{endpoint}"
|
|
30
|
+
response = requests.request(
|
|
31
|
+
method=method,
|
|
32
|
+
url=url,
|
|
33
|
+
params=params,
|
|
34
|
+
json=json_data,
|
|
35
|
+
headers=self.headers,
|
|
36
|
+
timeout=30,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if not response.ok:
|
|
40
|
+
self._handle_error_response(response)
|
|
41
|
+
|
|
42
|
+
return response.json()
|
|
43
|
+
|
|
44
|
+
def _handle_error_response(self, response):
|
|
45
|
+
"""Handle API error response with specific error types."""
|
|
46
|
+
status = response.status_code
|
|
47
|
+
|
|
48
|
+
# Rate limit (429)
|
|
49
|
+
if status == 429:
|
|
50
|
+
retry_after, limit, remaining = parse_rate_limit_from_response(response)
|
|
51
|
+
raise RateLimitError(
|
|
52
|
+
retry_after=retry_after,
|
|
53
|
+
limit=limit,
|
|
54
|
+
remaining=remaining,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Authentication errors (401, 403)
|
|
58
|
+
if status in (401, 403):
|
|
59
|
+
raise AuthError(f"Authentication failed: {response.text}")
|
|
60
|
+
|
|
61
|
+
# Not found (404)
|
|
62
|
+
if status == 404:
|
|
63
|
+
# Try to determine resource type from URL
|
|
64
|
+
url = response.request.url
|
|
65
|
+
if "/posts/" in url:
|
|
66
|
+
raise NotFoundError("post")
|
|
67
|
+
elif "/submolts/" in url:
|
|
68
|
+
raise NotFoundError("submolt")
|
|
69
|
+
else:
|
|
70
|
+
raise NotFoundError("resource")
|
|
71
|
+
|
|
72
|
+
# Other errors
|
|
73
|
+
raise Exception(f"API error: {status} {response.text}")
|
|
74
|
+
|
|
75
|
+
def get(self, endpoint: str, params: Optional[dict] = None) -> dict:
|
|
76
|
+
"""GET request."""
|
|
77
|
+
return self._request("GET", endpoint, params=params)
|
|
78
|
+
|
|
79
|
+
def post(
|
|
80
|
+
self, endpoint: str, json_data: Optional[dict] = None
|
|
81
|
+
) -> dict:
|
|
82
|
+
"""POST request."""
|
|
83
|
+
return self._request("POST", endpoint, json_data=json_data)
|
|
84
|
+
|
|
85
|
+
def delete(self, endpoint: str) -> dict:
|
|
86
|
+
"""DELETE request."""
|
|
87
|
+
return self._request("DELETE", endpoint)
|
moltcli/utils/config.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Config loader for MoltCLI."""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Config:
|
|
9
|
+
"""Config loader for credentials and settings."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, config_path: Optional[str] = None):
|
|
12
|
+
if config_path is None:
|
|
13
|
+
config_path = os.environ.get(
|
|
14
|
+
"MOLTCLI_CONFIG_PATH",
|
|
15
|
+
str(Path(__file__).parent.parent.parent / "credentials.json")
|
|
16
|
+
)
|
|
17
|
+
self.config_path = Path(config_path)
|
|
18
|
+
self._config: Optional[dict] = None
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def config(self) -> dict:
|
|
22
|
+
"""Load and cache config."""
|
|
23
|
+
if self._config is None:
|
|
24
|
+
if not self.config_path.exists():
|
|
25
|
+
raise FileNotFoundError(f"Config not found: {self.config_path}")
|
|
26
|
+
with open(self.config_path) as f:
|
|
27
|
+
self._config = json.load(f)
|
|
28
|
+
return self._config
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def api_key(self) -> str:
|
|
32
|
+
"""Get API key from config."""
|
|
33
|
+
key = self.config.get("api_key")
|
|
34
|
+
if not key:
|
|
35
|
+
raise ValueError("api_key not found in config")
|
|
36
|
+
return key
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def agent_name(self) -> str:
|
|
40
|
+
"""Get agent name from config."""
|
|
41
|
+
return self.config.get("agent_name", "unknown")
|
|
42
|
+
|
|
43
|
+
def get(self, key: str, default=None):
|
|
44
|
+
"""Get config value by key."""
|
|
45
|
+
return self.config.get(key, default)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Global config instance
|
|
49
|
+
_config: Optional[Config] = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_config() -> Config:
|
|
53
|
+
"""Get global config instance."""
|
|
54
|
+
global _config
|
|
55
|
+
if _config is None:
|
|
56
|
+
_config = Config()
|
|
57
|
+
return _config
|
moltcli/utils/errors.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Error codes and error handler for MoltCLI."""
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Error codes
|
|
6
|
+
AUTH_INVALID = "AUTH_INVALID"
|
|
7
|
+
AUTH_MISSING = "AUTH_MISSING"
|
|
8
|
+
POST_NOT_FOUND = "POST_NOT_FOUND"
|
|
9
|
+
SUBMOLT_NOT_FOUND = "SUBMOLT_NOT_FOUND"
|
|
10
|
+
RATE_LIMIT = "RATE_LIMIT"
|
|
11
|
+
NETWORK_ERROR = "NETWORK_ERROR"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MoltCLIError(Exception):
|
|
15
|
+
"""Base error for MoltCLI."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, message: str, code: str, suggestion: Optional[str] = None):
|
|
18
|
+
self.message = message
|
|
19
|
+
self.code = code
|
|
20
|
+
self.suggestion = suggestion
|
|
21
|
+
super().__init__(message)
|
|
22
|
+
|
|
23
|
+
def to_dict(self) -> dict:
|
|
24
|
+
"""Convert to error response dict."""
|
|
25
|
+
return {
|
|
26
|
+
"status": "error",
|
|
27
|
+
"error_code": self.code,
|
|
28
|
+
"message": self.message,
|
|
29
|
+
"suggestion": self.suggestion,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AuthError(MoltCLIError):
|
|
34
|
+
"""Authentication error."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, message: str):
|
|
37
|
+
super().__init__(message, AUTH_INVALID, "Check your API key in credentials.json")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class NotFoundError(MoltCLIError):
|
|
41
|
+
"""Resource not found error."""
|
|
42
|
+
|
|
43
|
+
def __init__(self, resource: str):
|
|
44
|
+
super().__init__(
|
|
45
|
+
f"{resource} not found",
|
|
46
|
+
POST_NOT_FOUND if resource == "post" else SUBMOLT_NOT_FOUND,
|
|
47
|
+
f"Verify the {resource} exists and you have permission",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class RateLimitError(MoltCLIError):
|
|
52
|
+
"""Rate limit exceeded."""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
retry_after: Optional[int] = None,
|
|
57
|
+
limit: Optional[int] = None,
|
|
58
|
+
remaining: Optional[int] = None,
|
|
59
|
+
):
|
|
60
|
+
"""Initialize rate limit error.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
retry_after: Seconds until retry is allowed
|
|
64
|
+
limit: Rate limit maximum requests
|
|
65
|
+
remaining: Remaining requests in window
|
|
66
|
+
"""
|
|
67
|
+
self.retry_after = retry_after
|
|
68
|
+
self.limit = limit
|
|
69
|
+
self.remaining = remaining
|
|
70
|
+
|
|
71
|
+
# Build message
|
|
72
|
+
if retry_after:
|
|
73
|
+
message = f"Rate limit exceeded. Retry after {retry_after} seconds."
|
|
74
|
+
else:
|
|
75
|
+
message = "Rate limit exceeded. Please slow down."
|
|
76
|
+
|
|
77
|
+
# Build suggestion
|
|
78
|
+
if retry_after:
|
|
79
|
+
suggestion = f"Wait {retry_after} seconds before retrying."
|
|
80
|
+
else:
|
|
81
|
+
suggestion = "Wait a moment before retrying. Use --delay to space requests."
|
|
82
|
+
|
|
83
|
+
super().__init__(message, RATE_LIMIT, suggestion)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def handle_error(error: Exception) -> dict:
|
|
87
|
+
"""Convert exception to error response."""
|
|
88
|
+
if isinstance(error, MoltCLIError):
|
|
89
|
+
return error.to_dict()
|
|
90
|
+
return {
|
|
91
|
+
"status": "error",
|
|
92
|
+
"error_code": "UNKNOWN",
|
|
93
|
+
"message": str(error),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def parse_rate_limit_from_response(response) -> tuple:
|
|
98
|
+
"""Parse rate limit info from API response.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
response: requests.Response object
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Tuple of (retry_after, limit, remaining)
|
|
105
|
+
"""
|
|
106
|
+
# Try common rate limit headers
|
|
107
|
+
retry_after = None
|
|
108
|
+
limit = None
|
|
109
|
+
remaining = None
|
|
110
|
+
|
|
111
|
+
# Retry-After header (seconds)
|
|
112
|
+
if "Retry-After" in response.headers:
|
|
113
|
+
try:
|
|
114
|
+
retry_after = int(response.headers["Retry-After"])
|
|
115
|
+
except ValueError:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
# X-RateLimit headers (common pattern)
|
|
119
|
+
if "X-RateLimit-Limit" in response.headers:
|
|
120
|
+
try:
|
|
121
|
+
limit = int(response.headers["X-RateLimit-Limit"])
|
|
122
|
+
except ValueError:
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
if "X-RateLimit-Remaining" in response.headers:
|
|
126
|
+
try:
|
|
127
|
+
remaining = int(response.headers["X-RateLimit-Remaining"])
|
|
128
|
+
except ValueError:
|
|
129
|
+
pass
|
|
130
|
+
|
|
131
|
+
# Also check response body for rate limit info
|
|
132
|
+
try:
|
|
133
|
+
body = response.json()
|
|
134
|
+
if isinstance(body, dict):
|
|
135
|
+
if "retry_after" in body:
|
|
136
|
+
retry_after = body["retry_after"]
|
|
137
|
+
if "rate_limit" in body:
|
|
138
|
+
rl = body["rate_limit"]
|
|
139
|
+
if isinstance(rl, dict):
|
|
140
|
+
limit = rl.get("limit", limit)
|
|
141
|
+
remaining = rl.get("remaining", remaining)
|
|
142
|
+
except Exception:
|
|
143
|
+
pass
|
|
144
|
+
|
|
145
|
+
return retry_after, limit, remaining
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Output formatter for MoltCLI."""
|
|
2
|
+
import json
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class OutputFormatter:
|
|
7
|
+
"""Handle JSON vs human-readable output."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, json_mode: bool = False):
|
|
10
|
+
self.json_mode = json_mode
|
|
11
|
+
|
|
12
|
+
def format(self, data: Any) -> str:
|
|
13
|
+
"""Format data for output."""
|
|
14
|
+
if self.json_mode:
|
|
15
|
+
return json.dumps(data, ensure_ascii=False, indent=2)
|
|
16
|
+
return self._humanize(data)
|
|
17
|
+
|
|
18
|
+
def _humanize(self, data: Any, indent: int = 0) -> str:
|
|
19
|
+
"""Convert to human-readable format."""
|
|
20
|
+
if isinstance(data, dict):
|
|
21
|
+
lines = []
|
|
22
|
+
for k, v in data.items():
|
|
23
|
+
if isinstance(v, (dict, list)):
|
|
24
|
+
lines.append(f"{k}:")
|
|
25
|
+
lines.append(self._humanize(v, indent + 2))
|
|
26
|
+
else:
|
|
27
|
+
lines.append(f"{k}: {v}")
|
|
28
|
+
return "\n".join(lines)
|
|
29
|
+
elif isinstance(data, list):
|
|
30
|
+
if not data:
|
|
31
|
+
return "(empty)"
|
|
32
|
+
lines = []
|
|
33
|
+
for i, item in enumerate(data, 1):
|
|
34
|
+
lines.append(f" {i}. {self._humanize(item, indent + 1)}")
|
|
35
|
+
return "\n".join(lines)
|
|
36
|
+
return str(data)
|
|
37
|
+
|
|
38
|
+
def print(self, data: Any) -> None:
|
|
39
|
+
"""Print formatted output."""
|
|
40
|
+
print(self.format(data))
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moltcli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI tool for Moltbook social network, AI Agent friendly
|
|
5
|
+
Author: MoltCLI Team
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: cli,moltbook,social,ai,agent
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: click>=8.0
|
|
19
|
+
Requires-Dist: requests>=2.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
23
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# MoltCLI
|
|
27
|
+
|
|
28
|
+
CLI tool for Moltbook social network, designed for AI Agents.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# JSON output mode (recommended for AI agents)
|
|
40
|
+
moltcli --json feed --sort hot
|
|
41
|
+
|
|
42
|
+
# Human readable output
|
|
43
|
+
moltcli feed --sort hot --limit 20
|
|
44
|
+
|
|
45
|
+
# Create a post
|
|
46
|
+
moltcli post create --submolt ai --title "Hello World" --content "My first post"
|
|
47
|
+
|
|
48
|
+
# Search
|
|
49
|
+
moltcli search "AI agents"
|
|
50
|
+
|
|
51
|
+
# Upvote
|
|
52
|
+
moltcli vote up POST_ID
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Commands
|
|
56
|
+
|
|
57
|
+
| Command | Description |
|
|
58
|
+
|---------|-------------|
|
|
59
|
+
| `moltcli auth` | Authentication management |
|
|
60
|
+
| `moltcli post` | Create/get/delete posts |
|
|
61
|
+
| `moltcli comment` | Comment on posts |
|
|
62
|
+
| `moltcli feed` | Get timeline/feed |
|
|
63
|
+
| `moltcli search` | Semantic search |
|
|
64
|
+
| `moltcli vote` | Upvote/downvote |
|
|
65
|
+
| `moltcli submolts` | Submolt management |
|
|
66
|
+
|
|
67
|
+
## Options
|
|
68
|
+
|
|
69
|
+
| Option | Description |
|
|
70
|
+
|--------|-------------|
|
|
71
|
+
| `--json` | Output as JSON (recommended for AI) |
|
|
72
|
+
| `--verbose` | Enable verbose logging |
|
|
73
|
+
| `--quiet` | Suppress non-essential output |
|
|
74
|
+
|
|
75
|
+
## Authentication
|
|
76
|
+
|
|
77
|
+
API key should be configured in `credentials.json`:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"api_key": "moltbook_sk_..."
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Install with dev dependencies
|
|
89
|
+
pip install -e ".[dev]"
|
|
90
|
+
|
|
91
|
+
# Run tests
|
|
92
|
+
pytest tests/ -v
|
|
93
|
+
|
|
94
|
+
# Lint
|
|
95
|
+
ruff check moltcli/
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Architecture
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
moltcli/
|
|
102
|
+
├── cli.py # Click CLI entry point
|
|
103
|
+
├── core/ # Business logic
|
|
104
|
+
│ ├── auth.py
|
|
105
|
+
│ ├── post.py
|
|
106
|
+
│ ├── comment.py
|
|
107
|
+
│ ├── feed.py
|
|
108
|
+
│ ├── search.py
|
|
109
|
+
│ ├── vote.py
|
|
110
|
+
│ └── submolts.py
|
|
111
|
+
└── utils/ # Shared utilities
|
|
112
|
+
├── config.py
|
|
113
|
+
├── api_client.py
|
|
114
|
+
├── formatter.py
|
|
115
|
+
└── errors.py
|
|
116
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
moltcli/__init__.py,sha256=e7p2Cat3JV5cvVi0A3XGjA8fhwg9p00mWktYc-RJcsM,77
|
|
2
|
+
moltcli/cli.py,sha256=3S7QNzYxGJAaIs7dfYYIP73v75D6NukW7rTG_PUjnkE,11006
|
|
3
|
+
moltcli/core/__init__.py,sha256=Ow___Urg5hRu2AY0W9YNZihc8ILHmWLzE59BE-yR_lM,379
|
|
4
|
+
moltcli/core/auth.py,sha256=ZFpfQeE-Jyt75tHqb_eYJgwlUgb_sQzXO-rVNg5Q3qE,570
|
|
5
|
+
moltcli/core/comment.py,sha256=4zG-Zus3skOjBQklOg6D1wknFZyIyoywm1XgfzEXEIw,1090
|
|
6
|
+
moltcli/core/feed.py,sha256=GfXMP8ciLrh1_noNgeDntT0XjUQANMvbZ4xeLBjzK50,813
|
|
7
|
+
moltcli/core/post.py,sha256=bKIGn6NGDHyQoXekV1JCSIAsFGdGdXHmdpgDIjgY3Ho,1163
|
|
8
|
+
moltcli/core/search.py,sha256=_MkbaXXbAAEUL4pj_-E5P-AoAljSSuu59-o-PeYvWQs,832
|
|
9
|
+
moltcli/core/submolts.py,sha256=Fgq-AZQI03seWJGjTwN08OJM-n9_lQkY2oi6hG7N5Wg,1161
|
|
10
|
+
moltcli/core/vote.py,sha256=P5rbGnY-oeTf3nDBoKHDpkBA-jg8pm-X9re4JbYbEOk,966
|
|
11
|
+
moltcli/utils/__init__.py,sha256=-bfVKSN8rxaSrTkb3oYG6wmD_GYoR7xn-IMo6v2WxeA,526
|
|
12
|
+
moltcli/utils/api_client.py,sha256=Q5EZzvHwYE8Fr-G2_Yk3LrmKiAaCTP2eIhFT3blDwh8,2617
|
|
13
|
+
moltcli/utils/config.py,sha256=TctyM814QmSLDawQMPM2bNbac_3cto0Ewiao8Qt8w4U,1607
|
|
14
|
+
moltcli/utils/errors.py,sha256=8JmQ1SbP00DGl3XwGa0_zgqypiiVzHHkaw5r61CwV5U,4100
|
|
15
|
+
moltcli/utils/formatter.py,sha256=kLYCPJw1IsanGYKXA8XGEm8mDAnC_AlIYQwN5bFypCc,1313
|
|
16
|
+
moltcli-0.1.0.dist-info/licenses/LICENSE,sha256=EOduU9kNb_dRzzPmt7gJsVSxqTCYJeYl5C2POxT0rj8,1069
|
|
17
|
+
moltcli-0.1.0.dist-info/METADATA,sha256=wUIt8SHrXhA_sOVhsBRXHRgGVd0znEf-IhmyAYJdIEo,2585
|
|
18
|
+
moltcli-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
19
|
+
moltcli-0.1.0.dist-info/entry_points.txt,sha256=Cn6XRCOpVqQHJYqbjOCJ9LfePx6VYR_Gdn6MsoMtLq4,45
|
|
20
|
+
moltcli-0.1.0.dist-info/top_level.txt,sha256=3BuZXxTPE63yrySE7ET5eCy32LneFysqMiG-pfEQifw,8
|
|
21
|
+
moltcli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MoltCLI Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
moltcli
|