wei-data-shu 0.4.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 (30) hide show
  1. wei_data_shu-0.4.0/PKG-INFO +541 -0
  2. wei_data_shu-0.4.0/README.md +518 -0
  3. wei_data_shu-0.4.0/pyproject.toml +42 -0
  4. wei_data_shu-0.4.0/setup.cfg +4 -0
  5. wei_data_shu-0.4.0/tests/__init__.py +32 -0
  6. wei_data_shu-0.4.0/tests/test_utils.py +32 -0
  7. wei_data_shu-0.4.0/wei_data_shu/SQLManager.py +297 -0
  8. wei_data_shu-0.4.0/wei_data_shu/__init__.py +101 -0
  9. wei_data_shu-0.4.0/wei_data_shu/baseColor.py +41 -0
  10. wei_data_shu-0.4.0/wei_data_shu/chartsManager.py +53 -0
  11. wei_data_shu-0.4.0/wei_data_shu/database/__init__.py +5 -0
  12. wei_data_shu-0.4.0/wei_data_shu/docManager.py +2 -0
  13. wei_data_shu-0.4.0/wei_data_shu/excel/__init__.py +13 -0
  14. wei_data_shu-0.4.0/wei_data_shu/excelManager.py +1083 -0
  15. wei_data_shu-0.4.0/wei_data_shu/fileManager.py +63 -0
  16. wei_data_shu-0.4.0/wei_data_shu/mail/__init__.py +5 -0
  17. wei_data_shu-0.4.0/wei_data_shu/mailManager.py +109 -0
  18. wei_data_shu-0.4.0/wei_data_shu/ollamaManager.py +117 -0
  19. wei_data_shu-0.4.0/wei_data_shu/stringManager.py +109 -0
  20. wei_data_shu-0.4.0/wei_data_shu/text/__init__.py +32 -0
  21. wei_data_shu-0.4.0/wei_data_shu/text/_deps.py +64 -0
  22. wei_data_shu-0.4.0/wei_data_shu/text/analysis.py +66 -0
  23. wei_data_shu-0.4.0/wei_data_shu/text/forecast.py +168 -0
  24. wei_data_shu-0.4.0/wei_data_shu/textManager.py +117 -0
  25. wei_data_shu-0.4.0/wei_data_shu/timingTool.py +13 -0
  26. wei_data_shu-0.4.0/wei_data_shu.egg-info/PKG-INFO +541 -0
  27. wei_data_shu-0.4.0/wei_data_shu.egg-info/SOURCES.txt +28 -0
  28. wei_data_shu-0.4.0/wei_data_shu.egg-info/dependency_links.txt +1 -0
  29. wei_data_shu-0.4.0/wei_data_shu.egg-info/requires.txt +15 -0
  30. wei_data_shu-0.4.0/wei_data_shu.egg-info/top_level.txt +1 -0
@@ -0,0 +1,541 @@
1
+ Metadata-Version: 2.4
2
+ Name: wei-data-shu
3
+ Version: 0.4.0
4
+ Summary: Minimal data analysis techniques library
5
+ Author-email: Ethan Wilkins <thisluckyboy@126.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/phoenixlucky/wei-data-shu
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pandas
11
+ Requires-Dist: openpyxl
12
+ Requires-Dist: toml
13
+ Requires-Dist: mysql-connector-python
14
+ Requires-Dist: requests
15
+ Provides-Extra: analysis
16
+ Requires-Dist: numpy; extra == "analysis"
17
+ Requires-Dist: matplotlib; extra == "analysis"
18
+ Requires-Dist: statsmodels; extra == "analysis"
19
+ Requires-Dist: jieba; extra == "analysis"
20
+ Requires-Dist: wordcloud; extra == "analysis"
21
+ Provides-Extra: excel-client
22
+ Requires-Dist: xlwings; extra == "excel-client"
23
+
24
+ ## wei-data-shu
25
+
26
+ Minimal data analysis techniques library
27
+
28
+ `wei-data-shu` 一个用于简化办公工作的工具库,提供了数据库操作、Excel 处理、邮件发送、日期时间戳的格式转换、文件移动等常见功能,实现1到3行代码完成相关处理的快捷操作。
29
+
30
+ #### 📁项目结构
31
+
32
+ ```text
33
+ wei_data_shu/
34
+ ├─ wei_data_shu/ # 核心包
35
+ │ ├─ database/ # 数据库领域导出
36
+ │ ├─ excel/ # Excel 领域导出
37
+ │ ├─ text/ # 文本领域导出
38
+ │ └─ mail/ # 邮件领域导出
39
+ ├─ tests/ # 单元测试
40
+ ├─ pyproject.toml # 包配置
41
+ └─ README.md
42
+ ```
43
+
44
+ 结构说明:
45
+ - 核心代码统一放在 `wei_data_shu/` 包下;
46
+ - 测试代码放在 `tests/`,避免和发布包混在一起;
47
+ - 构建产物(`build/`、`dist/`、`*.egg-info`)不纳入版本控制。
48
+
49
+ #### 🔁兼容迁移说明(chartsManager 已弃用)
50
+
51
+ 旧路径仍可用(含弃用提示),建议迁移到新路径:
52
+
53
+ ```python
54
+ # 旧:from wei_data_shu.chartsManager import TrendPredictor, MultipleTrendPredictor, TextAnalysis
55
+
56
+ # 新:
57
+ from wei_data_shu.text.forecast import TrendPredictor, MultipleTrendPredictor
58
+ from wei_data_shu.text.analysis import TextAnalysis
59
+ ```
60
+
61
+ #### 🔌安装与升级
62
+
63
+ 使用以下命令安装 `wei-data-shu`:
64
+
65
+ ```bash
66
+ pip install wei-data-shu
67
+ ```
68
+
69
+ 安装可选能力(按需安装):
70
+
71
+ ```bash
72
+ # 文本分析/趋势预测(chartsManager、TextAnalysis 等)
73
+ pip install "wei-data-shu[analysis]"
74
+
75
+ # Excel 客户端能力(OpenExcel 的 Excel App 场景)
76
+ pip install "wei-data-shu[excel-client]"
77
+ ```
78
+
79
+ 使用以下命令升级 `wei-data-shu`:
80
+
81
+ ```bash
82
+ pip install wei-data-shu --upgrade
83
+ ```
84
+
85
+ #### 🔧功能
86
+
87
+ <!-- #### 1. Database 类 (可以连接各种数据库) 弃用
88
+ 用于连接和操作数据库。
89
+ ```python
90
+ from wei_data_shu import Database
91
+
92
+ # 示例代码
93
+ db = Database(host='your_host', port=3306, user='your_user', password='your_password', db='your_database')
94
+ result = db("SELECT * FROM your_table", operation_mode="s")
95
+ print(result)
96
+ ``` -->
97
+
98
+ #### 1. MySQLDatabase 类
99
+ 主要用于Mysql数据库的快速连接
100
+ ```python
101
+ from wei_data_shu import MySQLDatabase
102
+ ```
103
+ ##### 📌MySQL 连接配置
104
+ ```python
105
+ mysql_config = {
106
+ 'host': 'your_host',
107
+ 'port': 3306,
108
+ 'user': 'your_user',
109
+ 'password': 'your_password',
110
+ 'database': 'your_database'
111
+ }
112
+ ```
113
+ ##### ✏️创建 MySQLDatabase 对象
114
+ ```python
115
+ db = MySQLDatabase(mysql_config)
116
+ ```
117
+ ##### 📥插入数据
118
+ ```python
119
+ insert_query = "INSERT INTO your_table (column1, column2) VALUES (%s, %s)"
120
+ insert_params = ("value1", "value2")
121
+ db.execute_query(insert_query, insert_params)
122
+ ```
123
+ ##### 🔍查询数据
124
+ ```python
125
+ select_query = "SELECT * FROM your_table"
126
+ results = db.fetch_query(select_query)
127
+ for row in results:
128
+ print(row)
129
+ ```
130
+ ##### ⌛更新数据
131
+ ```python
132
+ update_query = "UPDATE your_table SET column1 = %s WHERE column2 = %s"
133
+ update_params = ("new_value", "value2")
134
+ db.execute_query(update_query, update_params)
135
+ ```
136
+ ##### 🔪删除数据
137
+ ```python
138
+ delete_query = "DELETE FROM your_table WHERE column1 = %s"
139
+ delete_params = ("new_value",)
140
+ db.execute_query(delete_query, delete_params)
141
+ ```
142
+ ##### 🚪关闭连接
143
+ ```python
144
+ db.close()
145
+ ```
146
+ ##### SQLAI智能聊天机器人
147
+ ```python
148
+ from wei_data_shu import SQLManager
149
+
150
+ # 示例代码
151
+ cfg = {
152
+ 'user': 'root',
153
+ 'password': '你的密码',
154
+ 'host': '127.0.0.1',
155
+ 'port': 3306,
156
+ 'database': 'mlcorpus'
157
+ }
158
+ db = SQLManager.MySQLDatabase(cfg)
159
+ db.run_ai_chatbot(chat_history_size=5, system_msg="System: You are a helpful AI assistant.")
160
+ ```
161
+
162
+ #### 2. Excel 相关类
163
+ 提供完整的 Excel 文件创建、读取、写入和操作功能。
164
+
165
+ ```python
166
+ from pathlib import Path
167
+ from wei_data_shu import ExcelManager, ExcelHandler, OpenExcel, ExcelOperation, quick_excel
168
+ ```
169
+
170
+ #### 2.1 ExcelManager 类(推荐使用)
171
+ 轻量级 Excel 工作簿管理类,基于 openpyxl,无需安装 Excel 应用。
172
+
173
+ **特性:**
174
+ - 自动创建不存在的文件
175
+ - 支持多工作表操作
176
+ - 快速读写数据
177
+ - 自动应用样式
178
+ - DataFrame 支持
179
+
180
+ ```python
181
+ from wei_data_shu import ExcelManager
182
+
183
+ # 创建或打开文件
184
+ wb = ExcelManager("data.xlsx")
185
+
186
+ # 写入数据(自动应用样式)
187
+ wb.write_sheet("Sheet1", [["Name", "Age"], ["Alice", 25]], start_row=1, start_col=1)
188
+
189
+ # 快速写入(自动计算范围)
190
+ wb.fast_write("Sheet1", [["Bob", 30]], start_row=3, start_col=1)
191
+
192
+ # 读取数据
193
+ data = wb.read_sheet("Sheet1", 1, 1)
194
+
195
+ # 使用上下文管理器(自动保存)
196
+ with ExcelManager("data.xlsx") as wb:
197
+ wb.fast_write("Sheet1", [[1, 2], [3, 4]], 1, 1)
198
+
199
+ # 保存并关闭
200
+ wb.save()
201
+ wb.close()
202
+ ```
203
+
204
+ **DataFrame 支持:**
205
+ ```python
206
+ import pandas as pd
207
+ from wei_data_shu import ExcelManager
208
+
209
+ df = pd.DataFrame({"Name": ["Alice", "Bob"], "Age": [25, 30]})
210
+
211
+ # DataFrame 写入 Excel
212
+ with ExcelManager("data.xlsx") as wb:
213
+ wb.write_dataframe("Sheet1", df)
214
+
215
+ # Excel 读取为 DataFrame
216
+ with ExcelManager("data.xlsx") as wb:
217
+ df = wb.read_dataframe("Sheet1")
218
+ ```
219
+
220
+ **工作表管理:**
221
+ ```python
222
+ from wei_data_shu import ExcelManager
223
+
224
+ wb = ExcelManager("data.xlsx")
225
+
226
+ # 创建新工作表
227
+ wb.create_sheet("NewSheet")
228
+
229
+ # 获取工作表信息
230
+ info = wb.get_sheet_info("Sheet1")
231
+ print(info)
232
+
233
+ # 复制工作表
234
+ wb.copy_sheet("Sheet1", "Sheet1_Copy")
235
+
236
+ # 删除工作表
237
+ wb.delete_sheet("OldSheet")
238
+ ```
239
+
240
+ #### 2.2 快速创建与读取
241
+ 一行代码完成常用操作:
242
+
243
+ ```python
244
+ from wei_data_shu import quick_excel, read_excel_quick
245
+
246
+ # 快速创建并写入数据
247
+ wb = quick_excel("data.xlsx", [["Name", "Age"], ["Alice", 25]])
248
+
249
+ # 快速读取为列表
250
+ data = read_excel_quick("data.xlsx")
251
+
252
+ # 快速读取为 DataFrame
253
+ df = read_excel_quick("data.xlsx", as_dataframe=True)
254
+ ```
255
+
256
+ #### 2.3 ExcelHandler 类(兼容版)
257
+ 面向已有文件的读取/写入工具,为兼容性保留。
258
+
259
+ ```python
260
+ from wei_data_shu import ExcelHandler
261
+
262
+ eh = ExcelHandler("data.xlsx")
263
+
264
+ # 写入指定范围
265
+ eh.excel_write("Sheet1", [[1, 2], [3, 4]], 1, 1, 2, 2)
266
+
267
+ # 读取指定范围
268
+ data = eh.excel_read("Sheet1", 1, 1, 2, 2)
269
+
270
+ # 另存为
271
+ eh.excel_save_as("output.xlsx")
272
+
273
+ # 关闭
274
+ eh.excel_quit()
275
+ ```
276
+
277
+ #### 2.4 OpenExcel 类(Excel 应用操作)
278
+ 通过 Excel 应用打开工作簿,适合需要 RefreshAll 的场景。
279
+ **注意:需要安装 Microsoft Excel**
280
+
281
+ ```python
282
+ from wei_data_shu import OpenExcel
283
+
284
+ # 使用上下文管理器自动保存
285
+ with OpenExcel("data.xlsx").my_open() as wb:
286
+ wb.fast_write("Sheet1", [[1, 2], [3, 4]], 1, 1)
287
+
288
+ # 刷新数据连接(需要 Excel 应用)
289
+ with OpenExcel("data.xlsx").open_save_Excel() as appwb:
290
+ appwb.api.RefreshAll()
291
+
292
+ # 列出工作表并按关键词过滤
293
+ sheets = OpenExcel("data.xlsx").file_show(filter=["sheet", "报表"])
294
+ print(sheets)
295
+ ```
296
+
297
+ #### 2.5 ExcelOperation 类(数据处理)
298
+ 提供数据拆分、合并等高级操作。
299
+
300
+ ```python
301
+ from wei_data_shu import ExcelOperation
302
+
303
+ # 按工作表拆分为多个文件
304
+ op = ExcelOperation("data.xlsx", "output_folder")
305
+ files = op.split_table()
306
+
307
+ # 合并多个文件
308
+ op.merge_tables(["file1.xlsx", "file2.xlsx"], "merged.xlsx")
309
+
310
+ # 转换为 CSV
311
+ csv_path = op.convert_to_csv()
312
+ ```
313
+
314
+ #### 2.6 完整流水线示例
315
+ ```python
316
+ from pathlib import Path
317
+ from wei_data_shu import ExcelManager, OpenExcel, ExcelOperation
318
+
319
+ base = Path.cwd()
320
+ f = str(base / "pipeline.xlsx")
321
+
322
+ # 1) 创建并写入数据
323
+ with ExcelManager(f) as wb:
324
+ wb.fast_write("Sheet1", [["Name", "Age"], ["Alice", 25], ["Bob", 30]], 1, 1)
325
+
326
+ # 2) 通过 Excel 应用刷新(需要本机 Excel)
327
+ with OpenExcel(f).open_save_Excel() as appwb:
328
+ appwb.api.RefreshAll()
329
+
330
+ # 3) 拆分工作表到单文件
331
+ op = ExcelOperation(f, str(base / "output"))
332
+ op.split_table()
333
+
334
+ # 4) 转换为 CSV
335
+ csv_file = op.convert_to_csv()
336
+ ```
337
+
338
+ #### 3. eSend 类
339
+ 用于发送邮件。
340
+
341
+ ```python
342
+ from wei_data_shu import eSend
343
+
344
+ # 示例代码
345
+ email_sender = eSend(sender,receiver,username,password,smtpserver='smtp.126.com')
346
+ email_sender.send_email(subject='Your Subject', e_content='Your Email Content', file_paths=['/path/to/file/'], file_names=['attachment.txt'])
347
+ ```
348
+
349
+ #### 4. DateFormat 类
350
+ 用于获取最近的时间处理。
351
+
352
+ ```python
353
+ from wei_data_shu import DateFormat
354
+
355
+ # 示例代码
356
+ #timeclass:1日期 date 2时间戳 timestamp 3时刻 time 4datetime
357
+ #获取当日的日期字符串
358
+ x=DateFormat(interval_day=0,timeclass='date').get_timeparameter(Format="%Y-%m-%d")
359
+ print(x)
360
+
361
+ # 格式化df的表的列属性
362
+ df = DateFormat(interval_day=0,timeclass='date').datetime_standar(df, '日期')
363
+ ```
364
+
365
+ #### 5. FileManagement 类
366
+ 用于文件移动并且重命名。
367
+ ```python
368
+ #latest_folder2 当前目录
369
+ #destination_directory 目标目录
370
+ #target_files2 文件名
371
+ #add_prefix 重命名去除数字
372
+ #file_type 文件类型
373
+ FileManagement().copy_files(latest_folder2, destination_directory, target_files2, rename=True,file_type="xls")
374
+ #寻找最新文件夹
375
+ latest_folder = FileManagement().find_latest_folder(base_directory)
376
+ ```
377
+
378
+ #### 6. StringBaba 类
379
+ 用于清洗字符串。
380
+ ```python
381
+ from wei_data_shu import StringBaba
382
+
383
+ str="""
384
+ 萝卜
385
+ 白菜
386
+ """
387
+ formatted_str =StringBaba(str1).format_string_sql()
388
+ ```
389
+
390
+ #### 7. TextAnalysis 类
391
+ 用于进行词频分析。
392
+ ```python
393
+ from wei_data_shu import TextAnalysis
394
+ # 示例用法
395
+ data = {
396
+ 'Category': ['A', 'A', 'B', 'D', 'C'],
397
+ 'Text': [
398
+ '我爱自然语言处理',
399
+ '自然语言处理很有趣',
400
+ '机器学习是一门很有前途的学科',
401
+ '我对机器学习很感兴趣',
402
+ '数据科学包含很多有趣的内容'
403
+ ]
404
+ }
405
+
406
+ df = pd.DataFrame(data)
407
+
408
+ ta = TextAnalysis(df)
409
+ result = ta.get_word_freq(group_col='Category', text_col='Text', agg_func=' '.join)
410
+
411
+ word_freqs = result['word_freq'].tolist()
412
+ titles = result['Category'].tolist()
413
+
414
+ ta.plot_wordclouds(word_freqs, titles)
415
+ ```
416
+ #### 8. ChatBot类
417
+ 0.0.29新增,用于连接Ollama的AI接口
418
+
419
+ ```python
420
+ from wei_data_shu import ChatBot
421
+
422
+ bot = ChatBot(api_url='http://localhost:11434/api/chat')
423
+
424
+ print("开始聊天(输入 'exit' 退出,输入 'new' 新建聊天)")
425
+ while True:
426
+ user_input = input("你: ")
427
+ if user_input.lower() == 'exit':
428
+ break
429
+ elif user_input.lower() == 'new':
430
+ bot.start_new_chat()
431
+ continue
432
+
433
+ # 默认使用流式响应,可以根据需要选择非流式响应
434
+ bot.send_message(user_input, stream=True)
435
+
436
+ print("聊天结束。")
437
+ ```
438
+
439
+ ## 9 DailyEmailReport 类
440
+ 用于发送每日报告邮件,支持HTML和纯文本格式。
441
+
442
+ ```python
443
+ from wei_data_shu import DailyEmailReport
444
+
445
+ # 初始化 DailyEmailReport 实例
446
+ email_reporter = DailyEmailReport(
447
+ email_host='smtp.example.com',
448
+ email_port=465,
449
+ email_username='your_email@example.com',
450
+ email_password='your_password'
451
+ )
452
+
453
+ # 添加收件人
454
+ email_reporter.add_receiver('recipient@example.com')
455
+
456
+ # 发送纯文本邮件
457
+ text_content = """
458
+ Hello,
459
+
460
+ Here is your daily report.
461
+
462
+ [Insert your report content here.]
463
+
464
+ Regards,
465
+ Your Name
466
+ """
467
+ email_reporter.send_daily_report("Daily Report", text_content)
468
+
469
+ # 发送HTML邮件 - 方式1
470
+ html_content = """
471
+ <html>
472
+ <body>
473
+ <h1>Daily Report</h1>
474
+ <p>Hello,</p>
475
+ <p>Here is your <b>daily report</b>.</p>
476
+ <ul>
477
+ <li>Item 1</li>
478
+ <li>Item 2</li>
479
+ </ul>
480
+ <p>Regards,<br>
481
+ Your Name</p>
482
+ </body>
483
+ </html>
484
+ """
485
+ email_reporter.send_daily_report("HTML Report", html_content, is_html=True)
486
+
487
+ # 发送HTML邮件 - 方式2
488
+ email_reporter.send_daily_report("HTML Report", html_content=html_content)
489
+ ```
490
+
491
+ ## Contributing / 参与贡献
492
+
493
+ **English:** We welcome contributions! If you have any questions, suggestions, or improvements, please feel free to:
494
+ - [Submit an Issue](https://github.com/yourusername/wei-data-shu/issues) - Report bugs or request features
495
+ - [Submit a Pull Request](https://github.com/yourusername/wei-data-shu/pulls) - Contribute code
496
+
497
+ **中文:** 我们欢迎并感谢您的贡献!如果您有任何问题、建议或改进,请随时:
498
+ - [提交 Issue](https://github.com/yourusername/wei-data-shu/issues) - 报告 bug 或提出功能建议
499
+ - [提交 Pull Request](https://github.com/yourusername/wei-data-shu/pulls) - 贡献代码
500
+
501
+ ---
502
+
503
+ ## License / 许可证
504
+
505
+ **Copyright © 2026 Ethan Wilkins. All rights reserved.**
506
+
507
+ **English:** This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
508
+
509
+ **中文:** 本项目采用 [MIT 许可证](https://opensource.org/licenses/MIT) 开源许可。
510
+
511
+ ```
512
+ MIT License
513
+
514
+ Copyright (c) 2026 Ethan Wilkins
515
+
516
+ Permission is hereby granted, free of charge, to any person obtaining a copy
517
+ of this software and associated documentation files (the "Software"), to deal
518
+ in the Software without restriction, including without limitation the rights
519
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
520
+ copies of the Software, and to permit persons to whom the Software is
521
+ furnished to do so, subject to the following conditions:
522
+
523
+ The above copyright notice and this permission notice shall be included in all
524
+ copies or substantial portions of the Software.
525
+
526
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
527
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
528
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
529
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
530
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
531
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
532
+ SOFTWARE.
533
+ ```
534
+
535
+ ---
536
+
537
+ **免责声明 / Disclaimer:**
538
+
539
+ **English:** This software is provided "as is", without warranty of any kind, express or implied. The authors or copyright holders shall not be liable for any claims, damages, or other liabilities arising from the use of this software.
540
+
541
+ **中文:** 本软件按"原样"提供,不附带任何明示或暗示的担保。在任何情况下,作者或版权所有者均不对因使用本软件而产生的任何索赔、损害或其他责任承担责任。