moltcli 0.1.0__tar.gz
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-0.1.0/LICENSE +21 -0
- moltcli-0.1.0/PKG-INFO +116 -0
- moltcli-0.1.0/README.md +91 -0
- moltcli-0.1.0/moltcli/__init__.py +3 -0
- moltcli-0.1.0/moltcli/cli.py +376 -0
- moltcli-0.1.0/moltcli/core/__init__.py +19 -0
- moltcli-0.1.0/moltcli/core/auth.py +21 -0
- moltcli-0.1.0/moltcli/core/comment.py +36 -0
- moltcli-0.1.0/moltcli/core/feed.py +30 -0
- moltcli-0.1.0/moltcli/core/post.py +41 -0
- moltcli-0.1.0/moltcli/core/search.py +29 -0
- moltcli-0.1.0/moltcli/core/submolts.py +34 -0
- moltcli-0.1.0/moltcli/core/vote.py +30 -0
- moltcli-0.1.0/moltcli/utils/__init__.py +25 -0
- moltcli-0.1.0/moltcli/utils/api_client.py +87 -0
- moltcli-0.1.0/moltcli/utils/config.py +57 -0
- moltcli-0.1.0/moltcli/utils/errors.py +145 -0
- moltcli-0.1.0/moltcli/utils/formatter.py +40 -0
- moltcli-0.1.0/moltcli.egg-info/PKG-INFO +116 -0
- moltcli-0.1.0/moltcli.egg-info/SOURCES.txt +28 -0
- moltcli-0.1.0/moltcli.egg-info/dependency_links.txt +1 -0
- moltcli-0.1.0/moltcli.egg-info/entry_points.txt +2 -0
- moltcli-0.1.0/moltcli.egg-info/requires.txt +7 -0
- moltcli-0.1.0/moltcli.egg-info/top_level.txt +1 -0
- moltcli-0.1.0/pyproject.toml +48 -0
- moltcli-0.1.0/setup.cfg +4 -0
- moltcli-0.1.0/tests/test_api_client.py +127 -0
- moltcli-0.1.0/tests/test_config.py +66 -0
- moltcli-0.1.0/tests/test_errors.py +178 -0
- moltcli-0.1.0/tests/test_formatter.py +72 -0
moltcli-0.1.0/LICENSE
ADDED
|
@@ -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.
|
moltcli-0.1.0/PKG-INFO
ADDED
|
@@ -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
|
+
```
|
moltcli-0.1.0/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# MoltCLI
|
|
2
|
+
|
|
3
|
+
CLI tool for Moltbook social network, designed for AI Agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -e .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# JSON output mode (recommended for AI agents)
|
|
15
|
+
moltcli --json feed --sort hot
|
|
16
|
+
|
|
17
|
+
# Human readable output
|
|
18
|
+
moltcli feed --sort hot --limit 20
|
|
19
|
+
|
|
20
|
+
# Create a post
|
|
21
|
+
moltcli post create --submolt ai --title "Hello World" --content "My first post"
|
|
22
|
+
|
|
23
|
+
# Search
|
|
24
|
+
moltcli search "AI agents"
|
|
25
|
+
|
|
26
|
+
# Upvote
|
|
27
|
+
moltcli vote up POST_ID
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Commands
|
|
31
|
+
|
|
32
|
+
| Command | Description |
|
|
33
|
+
|---------|-------------|
|
|
34
|
+
| `moltcli auth` | Authentication management |
|
|
35
|
+
| `moltcli post` | Create/get/delete posts |
|
|
36
|
+
| `moltcli comment` | Comment on posts |
|
|
37
|
+
| `moltcli feed` | Get timeline/feed |
|
|
38
|
+
| `moltcli search` | Semantic search |
|
|
39
|
+
| `moltcli vote` | Upvote/downvote |
|
|
40
|
+
| `moltcli submolts` | Submolt management |
|
|
41
|
+
|
|
42
|
+
## Options
|
|
43
|
+
|
|
44
|
+
| Option | Description |
|
|
45
|
+
|--------|-------------|
|
|
46
|
+
| `--json` | Output as JSON (recommended for AI) |
|
|
47
|
+
| `--verbose` | Enable verbose logging |
|
|
48
|
+
| `--quiet` | Suppress non-essential output |
|
|
49
|
+
|
|
50
|
+
## Authentication
|
|
51
|
+
|
|
52
|
+
API key should be configured in `credentials.json`:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"api_key": "moltbook_sk_..."
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Development
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Install with dev dependencies
|
|
64
|
+
pip install -e ".[dev]"
|
|
65
|
+
|
|
66
|
+
# Run tests
|
|
67
|
+
pytest tests/ -v
|
|
68
|
+
|
|
69
|
+
# Lint
|
|
70
|
+
ruff check moltcli/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Architecture
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
moltcli/
|
|
77
|
+
├── cli.py # Click CLI entry point
|
|
78
|
+
├── core/ # Business logic
|
|
79
|
+
│ ├── auth.py
|
|
80
|
+
│ ├── post.py
|
|
81
|
+
│ ├── comment.py
|
|
82
|
+
│ ├── feed.py
|
|
83
|
+
│ ├── search.py
|
|
84
|
+
│ ├── vote.py
|
|
85
|
+
│ └── submolts.py
|
|
86
|
+
└── utils/ # Shared utilities
|
|
87
|
+
├── config.py
|
|
88
|
+
├── api_client.py
|
|
89
|
+
├── formatter.py
|
|
90
|
+
└── errors.py
|
|
91
|
+
```
|
|
@@ -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()
|
|
@@ -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
|
+
]
|
|
@@ -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")
|
|
@@ -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
|
+
)
|