klnote 0.1.0__tar.gz → 0.2.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.
Files changed (27) hide show
  1. {klnote-0.1.0 → klnote-0.2.0}/PKG-INFO +9 -2
  2. {klnote-0.1.0 → klnote-0.2.0}/README.md +7 -1
  3. klnote-0.2.0/klnote/__init__.py +3 -0
  4. {klnote-0.1.0 → klnote-0.2.0}/klnote/cli.py +35 -34
  5. klnote-0.2.0/klnote/core/__init__.py +3 -0
  6. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/service.py +27 -2
  7. {klnote-0.1.0 → klnote-0.2.0}/klnote.egg-info/PKG-INFO +9 -2
  8. {klnote-0.1.0 → klnote-0.2.0}/klnote.egg-info/requires.txt +1 -0
  9. {klnote-0.1.0 → klnote-0.2.0}/pyproject.toml +2 -1
  10. klnote-0.1.0/klnote/core/__init__.py +0 -0
  11. klnote-0.1.0/klnote/core/schema/__init__.py +0 -0
  12. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/constants.py +0 -0
  13. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/database.py +0 -0
  14. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/exceptions.py +0 -0
  15. {klnote-0.1.0/klnote → klnote-0.2.0/klnote/core/schema}/__init__.py +0 -0
  16. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/schema/schame.py +0 -0
  17. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/utils/__init__.py +0 -0
  18. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/utils/db.py +0 -0
  19. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/utils/editor.py +0 -0
  20. {klnote-0.1.0 → klnote-0.2.0}/klnote/core/utils/time_1.py +0 -0
  21. {klnote-0.1.0 → klnote-0.2.0}/klnote.egg-info/SOURCES.txt +0 -0
  22. {klnote-0.1.0 → klnote-0.2.0}/klnote.egg-info/dependency_links.txt +0 -0
  23. {klnote-0.1.0 → klnote-0.2.0}/klnote.egg-info/entry_points.txt +0 -0
  24. {klnote-0.1.0 → klnote-0.2.0}/klnote.egg-info/top_level.txt +0 -0
  25. {klnote-0.1.0 → klnote-0.2.0}/setup.cfg +0 -0
  26. {klnote-0.1.0 → klnote-0.2.0}/tests/test_cli.py +0 -0
  27. {klnote-0.1.0 → klnote-0.2.0}/tests/test_service.py +0 -0
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: klnote
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Stock note management tool
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
7
7
  Requires-Dist: click>=8.0.0
8
+ Requires-Dist: prettytable>=3.0.0
8
9
  Provides-Extra: dev
9
10
  Requires-Dist: pytest>=8.0.0; extra == "dev"
10
11
 
@@ -62,12 +63,18 @@ klnote --help
62
63
  ### 股票操作 (stk)
63
64
 
64
65
  ```
65
- klnote stk ls # 列出所有股票
66
+ klnote stk ls # 列出所有股票(表格对齐)
66
67
  klnote stk add <code> [-n name] [-d desc] # 添加股票
67
68
  klnote stk get <identifier> # 查看股票详情
68
69
  klnote stk delete <identifier> # 删除股票
69
70
  ```
70
71
 
72
+ **输出示例:**
73
+ ```
74
+ id code name description note_num created_at updated_at
75
+ 38578199c19644ebab18ce7b5c16d699 688102 斯瑞新财 None 1 2026-06-04T15:52:20.853674Z None
76
+ ```
77
+
71
78
  ### 笔记操作 (note)
72
79
 
73
80
  ```
@@ -52,12 +52,18 @@ klnote --help
52
52
  ### 股票操作 (stk)
53
53
 
54
54
  ```
55
- klnote stk ls # 列出所有股票
55
+ klnote stk ls # 列出所有股票(表格对齐)
56
56
  klnote stk add <code> [-n name] [-d desc] # 添加股票
57
57
  klnote stk get <identifier> # 查看股票详情
58
58
  klnote stk delete <identifier> # 删除股票
59
59
  ```
60
60
 
61
+ **输出示例:**
62
+ ```
63
+ id code name description note_num created_at updated_at
64
+ 38578199c19644ebab18ce7b5c16d699 688102 斯瑞新财 None 1 2026-06-04T15:52:20.853674Z None
65
+ ```
66
+
61
67
  ### 笔记操作 (note)
62
68
 
63
69
  ```
@@ -0,0 +1,3 @@
1
+ __version__ = "0.2.0"
2
+ __author__ = "zimvir"
3
+ __email__ = "zimvir@qq.com"
@@ -1,5 +1,9 @@
1
1
  import click
2
- from klnote.core.service import Service
2
+
3
+ from prettytable import PrettyTable
4
+
5
+ from klnote.core import Service
6
+
3
7
 
4
8
  service = Service()
5
9
 
@@ -10,29 +14,6 @@ def cli():
10
14
  pass
11
15
 
12
16
 
13
- def search_by_identifier(identifier: str):
14
- """
15
- 股票标识符解析,返回 stock id 列表
16
-
17
- 解析逻辑:
18
- 1. UUID格式(32位十六进制) → search(id=)
19
- 2. 纯数字 → search(code=)
20
- 3. 其他(字母/中文混合) → search(code=) 优先,search(name=) 兜底
21
- """
22
- import re
23
- # UUID → id
24
- if re.fullmatch(r'[0-9a-f]{32}', identifier):
25
- return service.search(id=identifier)
26
-
27
- # 纯数字 → code
28
- if identifier.isdigit():
29
- return service.search(code=identifier)
30
-
31
- # 其他(字母混合)→ 先试 code,再试 name
32
- ids = service.search(code=identifier)
33
- if not ids:
34
- ids = service.search(name=identifier)
35
- return ids
36
17
 
37
18
 
38
19
  # ============= stock 组 =============
@@ -49,8 +30,26 @@ def ls():
49
30
  if not stocks:
50
31
  click.echo("暂无股票")
51
32
  return
33
+ headers = ['id', 'code', 'name', 'description', 'note_num', 'created_at', 'updated_at']
34
+ pt = PrettyTable(headers)
35
+ pt.align = "l"
36
+ pt.horizontal_char = '-'
37
+ pt.border = False
52
38
  for s in stocks:
53
- click.echo(f"{s['id']}: {s['code']} {s.get('name', '')}")
39
+
40
+ rows = [
41
+ [
42
+ s.get("id") or "None",
43
+ s.get("code") or "None",
44
+ s.get("name") or "None",
45
+ s.get("description") or "None",
46
+ str(len(s.get("notes") or [])),
47
+ s.get("created_at") or "None",
48
+ s.get("updated_at") or "None"
49
+ ] for s in stocks
50
+ ]
51
+ pt.add_rows(rows)
52
+ click.echo(pt)
54
53
 
55
54
 
56
55
  @stk.command()
@@ -67,7 +66,7 @@ def add(code, name, description):
67
66
  @click.argument('identifier')
68
67
  def get(identifier):
69
68
  """查看股票详情(支持 id/code/name)"""
70
- stock_ids = search_by_identifier(identifier)
69
+ stock_ids = service.match_by_identifier(identifier)
71
70
  if not stock_ids:
72
71
  click.echo("未找到")
73
72
  return
@@ -86,7 +85,7 @@ def get(identifier):
86
85
  @click.argument('identifier')
87
86
  def delete(identifier):
88
87
  """删除股票(支持 id/code/name)"""
89
- stock_ids = search_by_identifier(identifier)
88
+ stock_ids = service.match_by_identifier(identifier)
90
89
  if not stock_ids:
91
90
  click.echo("未找到")
92
91
  return
@@ -108,7 +107,7 @@ def note():
108
107
  @click.option('-c', '--content', default='', help='笔记内容')
109
108
  def add(stock_identifier, summary, content):
110
109
  """添加笔记(支持 id/code/name)"""
111
- stock_ids = search_by_identifier(stock_identifier)
110
+ stock_ids = service.match_by_identifier(stock_identifier)
112
111
  if not stock_ids:
113
112
  click.echo("未找到股票")
114
113
  return
@@ -121,7 +120,7 @@ def add(stock_identifier, summary, content):
121
120
  @click.argument('stock_identifier')
122
121
  def ls(stock_identifier):
123
122
  """列出股票的所有笔记(支持 id/code/name)"""
124
- stock_ids = search_by_identifier(stock_identifier)
123
+ stock_ids = service.match_by_identifier(stock_identifier)
125
124
  if not stock_ids:
126
125
  click.echo("未找到股票")
127
126
  return
@@ -131,10 +130,12 @@ def ls(stock_identifier):
131
130
  click.echo(f"[{stock_id}] 暂无笔记")
132
131
  continue
133
132
  for i, n in enumerate(notes):
134
- click.echo(f"[{i}] {n.get('summary', '')}")
135
- click.echo(f" {n.get('content', '')}")
136
- click.echo(f" created: {n.get('created_at', '')}")
137
- click.echo("-"*50)
133
+ click.echo(f"索引: {i}")
134
+ click.echo(f"创建时间: {n.get('created_at', '')}")
135
+ click.echo(f"摘要: {n.get('summary', '')}")
136
+ if n.get('content'):
137
+ click.echo(f"内容: \n {n.get('content', '')}")
138
+ click.echo("-"*50)
138
139
 
139
140
 
140
141
  @note.command()
@@ -142,7 +143,7 @@ def ls(stock_identifier):
142
143
  @click.argument('index', type=int)
143
144
  def delete(stock_identifier, index):
144
145
  """删除笔记(支持 id/code/name)"""
145
- stock_ids = search_by_identifier(stock_identifier)
146
+ stock_ids = service.match_by_identifier(stock_identifier)
146
147
  if not stock_ids:
147
148
  click.echo("未找到股票")
148
149
  return
@@ -0,0 +1,3 @@
1
+ from .service import Service
2
+
3
+
@@ -1,5 +1,5 @@
1
1
  import json
2
-
2
+ import re
3
3
  from .database import Database
4
4
  from .constants import DB_PATH
5
5
  from .utils import get_iso_timestamp
@@ -10,7 +10,8 @@ class Service:
10
10
  self.db = db or Database(DB_PATH)
11
11
 
12
12
 
13
- def search(self,id:str=None, code:str=None, name:str=None):
13
+
14
+ def match_by_id_code_name(self,id:str=None, code:str=None, name:str=None):
14
15
  """
15
16
  id code name 三选一 查询,若多填, 优先 找 id 其次 code 最后 name
16
17
 
@@ -26,6 +27,30 @@ class Service:
26
27
 
27
28
  return ids
28
29
 
30
+ def match_by_identifier(self,identifier: str):
31
+ """
32
+ 股票标识符解析,返回 stock id 列表
33
+
34
+ 解析逻辑:
35
+ 1. UUID格式(32位十六进制) → search(id=)
36
+ 2. 纯数字 → search(code=)
37
+ 3. 其他(字母/中文混合) → search(code=) 优先,search(name=) 兜底
38
+ """
39
+
40
+ # UUID → id
41
+ if re.fullmatch(r'[0-9a-f]{32}', identifier):
42
+ return self.match_by_id_code_name(id=identifier)
43
+
44
+ # 纯数字 → code
45
+ if identifier.isdigit():
46
+ return self.match_by_id_code_name(code=identifier)
47
+
48
+ # 其他(字母混合)→ 先试 code,再试 name
49
+ ids = self.match_by_id_code_name(code=identifier)
50
+ if not ids:
51
+ ids = self.match_by_id_code_name(name=identifier)
52
+ return ids
53
+
29
54
  # stock
30
55
  def stock_add(self, code: str, id: str = None, name: str = None, description: str = None):
31
56
  """新建股票条目"""
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: klnote
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Stock note management tool
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
7
7
  Requires-Dist: click>=8.0.0
8
+ Requires-Dist: prettytable>=3.0.0
8
9
  Provides-Extra: dev
9
10
  Requires-Dist: pytest>=8.0.0; extra == "dev"
10
11
 
@@ -62,12 +63,18 @@ klnote --help
62
63
  ### 股票操作 (stk)
63
64
 
64
65
  ```
65
- klnote stk ls # 列出所有股票
66
+ klnote stk ls # 列出所有股票(表格对齐)
66
67
  klnote stk add <code> [-n name] [-d desc] # 添加股票
67
68
  klnote stk get <identifier> # 查看股票详情
68
69
  klnote stk delete <identifier> # 删除股票
69
70
  ```
70
71
 
72
+ **输出示例:**
73
+ ```
74
+ id code name description note_num created_at updated_at
75
+ 38578199c19644ebab18ce7b5c16d699 688102 斯瑞新财 None 1 2026-06-04T15:52:20.853674Z None
76
+ ```
77
+
71
78
  ### 笔记操作 (note)
72
79
 
73
80
  ```
@@ -1,4 +1,5 @@
1
1
  click>=8.0.0
2
+ prettytable>=3.0.0
2
3
 
3
4
  [dev]
4
5
  pytest>=8.0.0
@@ -4,11 +4,12 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "klnote"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "Stock note management tool"
9
9
  requires-python = ">=3.10"
10
10
  dependencies = [
11
11
  "click>=8.0.0",
12
+ "prettytable>=3.0.0",
12
13
  ]
13
14
  readme = "README.md"
14
15
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes