cppackage 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.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ CPpackage包
6
+
7
+ 一个提供实用工具和核心功能的Python包
8
+ """
9
+
10
+ __version__ = '0.1.0'
11
+ __author__ = 'CPpackage Team'
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ CPpackage核心功能模块
6
+
7
+ 提供包的核心功能和命令行工具
8
+ """
9
+
10
+ import sys
11
+
12
+
13
+ def execute_from_command_line(argv=None):
14
+ """执行命令行命令
15
+
16
+ Args:
17
+ argv: 命令行参数列表
18
+ """
19
+ if argv is None:
20
+ argv = sys.argv
21
+
22
+ # 这里可以添加命令行处理逻辑
23
+ print(f"执行命令: {' '.join(argv)}")
24
+
25
+
26
+ def main():
27
+ """主函数,用于命令行入口点"""
28
+ execute_from_command_line()
@@ -0,0 +1,2 @@
1
+ from .sql_model import sel_data, update_data, updata, update_datas, del_data, deldata, deldata_time, update_test
2
+ from .config import set_db_config, get_db_config
@@ -0,0 +1,24 @@
1
+ import os
2
+
3
+ _db_config = {
4
+ 'host': os.getenv('CPPACKAGE_DB_HOST'),
5
+ 'user': os.getenv('CPPACKAGE_DB_USER'),
6
+ 'password': os.getenv('CPPACKAGE_DB_PASSWORD'),
7
+ 'database': os.getenv('CPPACKAGE_DB_NAME'),
8
+ 'port': int(os.getenv('CPPACKAGE_DB_PORT', '3306')),
9
+ }
10
+
11
+ def set_db_config(host=None, user=None, password=None, database=None, port=None):
12
+ if host is not None:
13
+ _db_config['host'] = host
14
+ if user is not None:
15
+ _db_config['user'] = user
16
+ if password is not None:
17
+ _db_config['password'] = password
18
+ if database is not None:
19
+ _db_config['database'] = database
20
+ if port is not None:
21
+ _db_config['port'] = int(port)
22
+
23
+ def get_db_config():
24
+ return _db_config.copy()
@@ -0,0 +1,105 @@
1
+ import pymysql
2
+ import time
3
+ from pymysql import Error
4
+ from .config import get_db_config
5
+
6
+ def _get_connection(database=None, port=None):
7
+ cfg = get_db_config()
8
+ db = database if database is not None else cfg.get('database')
9
+ prt = port if port is not None else cfg.get('port', 3306)
10
+ return pymysql.connect(
11
+ host=cfg.get('host'),
12
+ user=cfg.get('user'),
13
+ password=cfg.get('password'),
14
+ database=db,
15
+ port=prt,
16
+ )
17
+
18
+ def sel_data(sql, port=None, database=None):
19
+ try:
20
+ conn = _get_connection(database=database, port=port)
21
+ cursor = conn.cursor()
22
+ cursor.execute(sql)
23
+ result = cursor.fetchall()
24
+ cursor.close()
25
+ conn.close()
26
+ return result
27
+ except pymysql.MySQLError as e:
28
+ print(f"An error occurred: {e}")
29
+
30
+ def update_data(sql, values, port=None, database=None):
31
+ conn = _get_connection(database=database, port=port)
32
+ cursor = conn.cursor()
33
+ cursor.execute(sql, values)
34
+ conn.commit()
35
+ cursor.close()
36
+ conn.close()
37
+
38
+ def updata(data, databases, table):
39
+ s = ""
40
+ st1 = ""
41
+ for i in data.columns.values:
42
+ s = s + "`" + i + "`,"
43
+ st1 = st1 + "%s,"
44
+ s = s[:-1]
45
+ st1 = st1[:-1]
46
+ all_data = []
47
+ for _, k in data.iterrows():
48
+ all_data.append(tuple(k.to_list()))
49
+ sql = 'INSERT INTO %s (%s) VALUES (%s)' % (table, s, st1)
50
+ update_datas(sql, tuple(all_data), database=databases)
51
+ time.sleep(2)
52
+
53
+ def deldata(all_del_list, id_name, table_name, database):
54
+ str11 = ""
55
+ for te in all_del_list:
56
+ if "str" in str(type(te)):
57
+ str11 = str11 + "'" + str(te) + "',"
58
+ else:
59
+ str11 = str11 + str(te) + ","
60
+ str11 = str11[:-1]
61
+ delsql = 'DELETE from `%s` where %s in (%s)' % (table_name, id_name, str11)
62
+ del_data(delsql, database=database)
63
+
64
+ def deldata_time(id_name, table_name, id, database, time_name, start_time, end_time):
65
+ delsql = 'DELETE from `%s` where %s = %s and `%s`>= "%s" and `%s`<= "%s"' % (
66
+ table_name, id_name, id, time_name, start_time, time_name, end_time
67
+ )
68
+ del_data(delsql, database=database)
69
+
70
+ def update_datas(sql, values, port=None, database=None):
71
+ with _get_connection(database=database, port=port) as conn:
72
+ with conn.cursor() as cursor:
73
+ cursor.executemany(sql, values)
74
+ conn.commit()
75
+
76
+ def del_data(sql, port=None, database=None):
77
+ try:
78
+ conn = _get_connection(database=database, port=port)
79
+ cursor = conn.cursor()
80
+ cursor.execute(sql)
81
+ conn.commit()
82
+ cursor.close()
83
+ conn.close()
84
+ except pymysql.MySQLError as e:
85
+ print(f"An error occurred: {e}")
86
+
87
+ def update_test(df, table_name, databases):
88
+ try:
89
+ conn = _get_connection(database=databases)
90
+ cursor = conn.cursor()
91
+ columns = ', '.join(df.columns)
92
+ values_template = ', '.join([f'({", ".join(["%s"] * len(df.columns))})'] * len(df))
93
+ update_clause = ', '.join([f'{col} = VALUES({col})' for col in df.columns if col != 'id'])
94
+ sql = f"INSERT INTO {table_name} ({columns}) VALUES {values_template} " \
95
+ f"ON DUPLICATE KEY UPDATE {update_clause}"
96
+ values = [tuple(row) for row in df.values]
97
+ flat_values = [item for sublist in values for item in sublist]
98
+ cursor.execute(sql, flat_values)
99
+ conn.commit()
100
+ print(f"成功插入/更新 {cursor.rowcount} 条记录")
101
+ except Error as e:
102
+ print(f"数据库错误: {e}")
103
+ finally:
104
+ if conn:
105
+ conn.close()
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ CPpackage工具模块
6
+
7
+ 提供各种实用工具函数
8
+ """
9
+
10
+
11
+ def helper_function():
12
+ """示例辅助函数
13
+
14
+ Returns:
15
+ str: 返回一个简单的消息
16
+ """
17
+ return "这是一个辅助函数"
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.1
2
+ Name: cppackage
3
+ Version: 0.1.0
4
+ Summary: 超品集团自用的Python包
5
+ Home-page: https://github.com/example/CPpackage
6
+ Author: team-数智组
7
+ Author-email: m110135@163.com
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: pymysql
21
+ Requires-Dist: pandas
22
+ Requires-Dist: numpy
23
+
24
+ # CPpackage
25
+
26
+ ## 简介
27
+
28
+ CPpackage是超品集团内部使用的Python包,核心功能集中在MySQL数据库增删改查功能以及部分数据清洗的能力。
29
+
30
+ ## 安装
31
+
32
+ ```bash
33
+ pip install CPpackage
34
+ ```
35
+
36
+ ## 使用方法
37
+
38
+ ```python
39
+ # 导入包
40
+ from CPpackage.db import set_db_config
41
+ from CPpackage.db.sql_model import sel_data, update_data, updata, update_datas, del_data, deldata, deldata_time, update_test
42
+
43
+ # 配置数据库连接(也可通过环境变量CPPACKAGE_DB_*配置)
44
+ set_db_config(host='your_host', user='your_user', password='your_password', database='your_database', port=3306)
45
+
46
+ # 查询示例
47
+ rows = sel_data('SELECT 1')
48
+ print(rows)
49
+ ```
50
+
51
+ ## 项目结构
52
+
53
+ ```
54
+ CPpackage/
55
+ ├── CPpackage/ # 主包
56
+ │ ├── core/ # 核心功能
57
+ │ ├── utils/ # 工具函数
58
+ │ └── db/ # 数据库功能与配置(sql_model拆解于此)
59
+ ├── manage.py # 管理脚本
60
+ ├── LICENSE # 许可证
61
+ ├── MANIFEST.in # 打包配置
62
+ ├── readme.md # 说明文档
63
+ └── setup.py # 安装配置
64
+ ```
65
+
66
+ ## 许可证
67
+
68
+ 本项目采用MIT许可证。详情请参阅LICENSE文件。
@@ -0,0 +1,24 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ readme.md
4
+ setup.py
5
+ CPpackage/__init__.py
6
+ CPpackage.egg-info/PKG-INFO
7
+ CPpackage.egg-info/SOURCES.txt
8
+ CPpackage.egg-info/dependency_links.txt
9
+ CPpackage.egg-info/entry_points.txt
10
+ CPpackage.egg-info/not-zip-safe
11
+ CPpackage.egg-info/requires.txt
12
+ CPpackage.egg-info/top_level.txt
13
+ CPpackage/core/__init__.py
14
+ CPpackage/db/__init__.py
15
+ CPpackage/db/config.py
16
+ CPpackage/db/sql_model.py
17
+ CPpackage/utils/__init__.py
18
+ cppackage.egg-info/PKG-INFO
19
+ cppackage.egg-info/SOURCES.txt
20
+ cppackage.egg-info/dependency_links.txt
21
+ cppackage.egg-info/entry_points.txt
22
+ cppackage.egg-info/not-zip-safe
23
+ cppackage.egg-info/requires.txt
24
+ cppackage.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ cppackage = CPpackage.core:main
@@ -0,0 +1,3 @@
1
+ pymysql
2
+ pandas
3
+ numpy
@@ -0,0 +1 @@
1
+ CPpackage
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 CPpackage
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,9 @@
1
+ include LICENSE
2
+ include readme.md
3
+ recursive-include CPpackage/core *
4
+ recursive-include CPpackage/utils *
5
+ recursive-include CPpackage/db *
6
+ global-exclude *.pyc
7
+ global-exclude __pycache__
8
+ global-exclude *.py[cod]
9
+ global-exclude *$py.class
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.1
2
+ Name: cppackage
3
+ Version: 0.1.0
4
+ Summary: 超品集团自用的Python包
5
+ Home-page: https://github.com/example/CPpackage
6
+ Author: team-数智组
7
+ Author-email: m110135@163.com
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: pymysql
21
+ Requires-Dist: pandas
22
+ Requires-Dist: numpy
23
+
24
+ # CPpackage
25
+
26
+ ## 简介
27
+
28
+ CPpackage是超品集团内部使用的Python包,核心功能集中在MySQL数据库增删改查功能以及部分数据清洗的能力。
29
+
30
+ ## 安装
31
+
32
+ ```bash
33
+ pip install CPpackage
34
+ ```
35
+
36
+ ## 使用方法
37
+
38
+ ```python
39
+ # 导入包
40
+ from CPpackage.db import set_db_config
41
+ from CPpackage.db.sql_model import sel_data, update_data, updata, update_datas, del_data, deldata, deldata_time, update_test
42
+
43
+ # 配置数据库连接(也可通过环境变量CPPACKAGE_DB_*配置)
44
+ set_db_config(host='your_host', user='your_user', password='your_password', database='your_database', port=3306)
45
+
46
+ # 查询示例
47
+ rows = sel_data('SELECT 1')
48
+ print(rows)
49
+ ```
50
+
51
+ ## 项目结构
52
+
53
+ ```
54
+ CPpackage/
55
+ ├── CPpackage/ # 主包
56
+ │ ├── core/ # 核心功能
57
+ │ ├── utils/ # 工具函数
58
+ │ └── db/ # 数据库功能与配置(sql_model拆解于此)
59
+ ├── manage.py # 管理脚本
60
+ ├── LICENSE # 许可证
61
+ ├── MANIFEST.in # 打包配置
62
+ ├── readme.md # 说明文档
63
+ └── setup.py # 安装配置
64
+ ```
65
+
66
+ ## 许可证
67
+
68
+ 本项目采用MIT许可证。详情请参阅LICENSE文件。
@@ -0,0 +1,45 @@
1
+ # CPpackage
2
+
3
+ ## 简介
4
+
5
+ CPpackage是超品集团内部使用的Python包,核心功能集中在MySQL数据库增删改查功能以及部分数据清洗的能力。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pip install CPpackage
11
+ ```
12
+
13
+ ## 使用方法
14
+
15
+ ```python
16
+ # 导入包
17
+ from CPpackage.db import set_db_config
18
+ from CPpackage.db.sql_model import sel_data, update_data, updata, update_datas, del_data, deldata, deldata_time, update_test
19
+
20
+ # 配置数据库连接(也可通过环境变量CPPACKAGE_DB_*配置)
21
+ set_db_config(host='your_host', user='your_user', password='your_password', database='your_database', port=3306)
22
+
23
+ # 查询示例
24
+ rows = sel_data('SELECT 1')
25
+ print(rows)
26
+ ```
27
+
28
+ ## 项目结构
29
+
30
+ ```
31
+ CPpackage/
32
+ ├── CPpackage/ # 主包
33
+ │ ├── core/ # 核心功能
34
+ │ ├── utils/ # 工具函数
35
+ │ └── db/ # 数据库功能与配置(sql_model拆解于此)
36
+ ├── manage.py # 管理脚本
37
+ ├── LICENSE # 许可证
38
+ ├── MANIFEST.in # 打包配置
39
+ ├── readme.md # 说明文档
40
+ └── setup.py # 安装配置
41
+ ```
42
+
43
+ ## 许可证
44
+
45
+ 本项目采用MIT许可证。详情请参阅LICENSE文件。
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from setuptools import setup, find_packages
5
+ import os
6
+
7
+ with open('readme.md', 'r', encoding='utf-8') as f:
8
+ long_description = f.read()
9
+
10
+ # 包的基本信息
11
+ setup(
12
+ name='cppackage',
13
+ version='0.1.0',
14
+ description='超品集团自用的Python包',
15
+ long_description=long_description,
16
+ long_description_content_type='text/markdown',
17
+ author='team-数智组',
18
+ author_email='m110135@163.com',
19
+ url='https://github.com/example/CPpackage',
20
+ packages=find_packages(),
21
+ include_package_data=True,
22
+ zip_safe=False,
23
+ classifiers=[
24
+ 'Development Status :: 3 - Alpha',
25
+ 'Intended Audience :: Developers',
26
+ 'License :: OSI Approved :: MIT License',
27
+ 'Programming Language :: Python :: 3',
28
+ 'Programming Language :: Python :: 3.8',
29
+ 'Programming Language :: Python :: 3.9',
30
+ 'Programming Language :: Python :: 3.10',
31
+ 'Programming Language :: Python :: 3.11',
32
+ 'Programming Language :: Python :: 3.12',
33
+ ],
34
+ python_requires='>=3.8',
35
+ install_requires=[
36
+ 'pymysql',
37
+ 'pandas',
38
+ 'numpy',
39
+ ],
40
+ entry_points={
41
+ 'console_scripts': [
42
+ 'cppackage=CPpackage.core:main',
43
+ ],
44
+ },
45
+ )