ddata 0.2.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.
ddata/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ from .date import DateUtil
2
+ date = DateUtil()
3
+
4
+ from .loggor import MyLoggor
5
+ log = MyLoggor()
6
+
7
+
8
+ # 将方法绑定到包级别,使得可以直接用包名调用
9
+ from.test import log_message
10
+ test = log_message
11
+
12
+
ddata/date.py ADDED
@@ -0,0 +1,148 @@
1
+ # -*- coding: utf-8 -*-
2
+ import datetime
3
+ import time
4
+
5
+
6
+ class DateUtil:
7
+ def __init__(self):
8
+ pass
9
+
10
+ @staticmethod
11
+ def date_2_hyphen_date(date):
12
+ """
13
+ 转成中划线日期
14
+ :param date:
15
+ :return:
16
+ """
17
+ res = date[0: 4] + '-' + date[4: 6] + '-'+date[6: 8]
18
+ return res
19
+
20
+ # 计算时间函数
21
+ @staticmethod
22
+ def timer(func):
23
+ def wrapper(*args, **kw):
24
+ start_time = time.time()
25
+ print(DateUtil.now(), '[%s] start to run program.........' % func.__name__)
26
+ ret = func(*args, **kw)
27
+ end_time = time.time()
28
+ # print(DateUtil.now(), "程序运行结束,共使用了{} 分钟".format(round((end_time - start_time) / 60, 2)))
29
+ print(DateUtil.now(), ' [%s] program is end, cost time: %.2f minute.........' % (func.__name__, round((end_time - start_time) / 60, 2)))
30
+ return ret
31
+
32
+ return wrapper
33
+
34
+ @staticmethod
35
+ def get_today():
36
+ formatter = "%Y%m%d"
37
+ today_val = datetime.date.today()
38
+ today = today_val.strftime(formatter)
39
+ return today
40
+
41
+ @staticmethod
42
+ def today(formatter):
43
+ """
44
+ 获取今天的日期的值
45
+ :param formatter: 日期的格式,默认为%Y%m%d,20170101
46
+ :return:
47
+ """
48
+ today_val = datetime.date.today()
49
+ if formatter is None or formatter == "":
50
+ formatter = "%Y%m%d"
51
+ today = today_val.strftime(formatter)
52
+ return today
53
+
54
+ @staticmethod
55
+ def yesterday(formatter=None):
56
+ today_val = datetime.date.today()
57
+ timedelta = datetime.timedelta(days=1)
58
+ yesterday_val = today_val - timedelta
59
+ if formatter is None or formatter == "":
60
+ formatter = "%Y%m%d"
61
+ yesterday = yesterday_val.strftime(formatter)
62
+ return yesterday
63
+
64
+ @staticmethod
65
+ def now():
66
+ """
67
+ 获取当前的时间
68
+ :param formatter: 时间的格式,比如%Y-%m-%d %H:%M:%S
69
+ :return:
70
+ """
71
+ formatter = "%Y-%m-%d %H:%M:%S.%f"
72
+ return datetime.datetime.now().strftime(formatter)[:-3]
73
+
74
+ @staticmethod
75
+ def formatter_now(formatter):
76
+ """
77
+ 获取当前的时间
78
+ :param formatter: 时间的格式,比如%Y-%m-%d %H:%M:%S
79
+ :return:
80
+ """
81
+ if formatter is None or formatter == "":
82
+ formatter = "%Y-%m-%d %H:%M:%S"
83
+
84
+ return time.strftime(formatter, time.localtime())
85
+
86
+ @staticmethod
87
+ def n_day_ago(date, n):
88
+ """
89
+ 获取n天之前的日期
90
+ :param date:
91
+ :param n:
92
+ :return:
93
+ """
94
+ if date is None or date == "":
95
+ date = datetime.date.today().strftime("%Y%m%d")
96
+
97
+ if n is None or n == "":
98
+ n = 1
99
+
100
+ one_day_ago = datetime.datetime.strptime(date, "%Y%m%d") + datetime.timedelta(
101
+ days=-n
102
+ )
103
+ return one_day_ago.strftime("%Y%m%d")
104
+
105
+ @staticmethod
106
+ def n_day_later(date, n):
107
+ """
108
+ 获取n天之后的日期
109
+ :param date:
110
+ :param n:
111
+ :return:
112
+ """
113
+ if date is None or date == "":
114
+ date = datetime.date.today().strftime("%Y%m%d")
115
+
116
+ if n is None or n == "":
117
+ n = 1
118
+
119
+ one_day_ago = datetime.datetime.strptime(date, "%Y%m%d") + datetime.timedelta(
120
+ days=n
121
+ )
122
+ return one_day_ago.strftime("%Y%m%d")
123
+
124
+ @staticmethod
125
+ def almost_n_month_ago(date, n):
126
+ """
127
+ 近似获取n月之前的日期,
128
+ :param date:
129
+ :param n:
130
+ :return:
131
+ """
132
+ if date is None or date == "":
133
+ date = datetime.date.today().strftime("%Y%m")
134
+
135
+ if n is None or n == "":
136
+ n = 1
137
+
138
+ date = date + "01"
139
+ one_day_ago = datetime.datetime.strptime(date, "%Y%m%d") + datetime.timedelta(
140
+ days=-n * 28
141
+ )
142
+ return one_day_ago.strftime("%Y%m")
143
+
144
+ @staticmethod
145
+ def timestamp_2_yyyy_mm(timestamp):
146
+ x = time.localtime(timestamp)
147
+ return time.strftime("%Y%m", x)
148
+
ddata/loggor.py ADDED
@@ -0,0 +1,30 @@
1
+ import logging.config
2
+
3
+
4
+ class MyLoggor():
5
+ # 配置日志记录器
6
+ logging.basicConfig(
7
+ level=logging.INFO,
8
+ format='%(asctime)s.%(msecs)03d %(levelname)s [%(threadName)s] %(message)s',
9
+ datefmt='%Y-%m-%d %H:%M:%S',
10
+ handlers=[logging.StreamHandler()]
11
+ )
12
+
13
+ def __get_logger(self):
14
+ logger = logging.getLogger(__name__)
15
+ return logger
16
+
17
+ def info(self, message):
18
+ self.__get_logger().info(message)
19
+
20
+ def warn(self, message):
21
+ self.__get_logger().warning(message)
22
+
23
+ def error(self):
24
+ self.__get_logger().error("hello")
25
+
26
+
27
+ if __name__ == "__main__":
28
+ log = MyLoggor()
29
+ log.info("hello")
30
+ print("hello")
ddata/test.py ADDED
@@ -0,0 +1,2 @@
1
+ def log_message(message):
2
+ print(f"Logging: {message}")
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.1
2
+ Name: ddata
3
+ Version: 0.2.0
4
+ Summary: A Python data package
5
+ Home-page: https://github.com/flyphant/ddata
6
+ Author: flyphant
7
+ Author-email: 576938286@qq.com
8
+ License: UNKNOWN
9
+ Keywords: python,package,sample
10
+ Platform: UNKNOWN
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.6, <4
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: numpy
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=3.7; extra == "dev"
19
+
20
+ # ddata
21
+
22
+ #### 介绍
23
+ python 常用数据分析工具包
24
+
25
+
26
+ #### 安装教程
27
+ pip install ddata
28
+
29
+ #### 使用说明
30
+
31
+
32
+
33
+ #### 参与贡献
34
+
35
+
36
+
37
+
38
+ #### 特技
39
+
40
+
41
+
42
+
@@ -0,0 +1,9 @@
1
+ ddata/__init__.py,sha256=mBjHCE78N6b-wmXS8O0mzcrCaVu3DRxyXqAFinXTV1M,210
2
+ ddata/date.py,sha256=l2Udj59-8jhxNyxRip2bkpSVQpmgcMlKB2yMzPYctGo,4099
3
+ ddata/loggor.py,sha256=WeB3NZtfcwlJApILUnB_d8YsT_f7BrydV8-SgsI0WH4,693
4
+ ddata/test.py,sha256=56mml8JwL7EVsj8gs3lYhoguOZnhMrrhicDi5M7JUUE,59
5
+ ddata-0.2.0.dist-info/METADATA,sha256=kgRew0e0pCyw1xEsusJS_rCMagw7jznEMFDHQP-prZs,692
6
+ ddata-0.2.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
7
+ ddata-0.2.0.dist-info/entry_points.txt,sha256=Dw04MzVHnZRz0qegRcphS-Wh0cMB80GRdKn7cZI6Vzc,68
8
+ ddata-0.2.0.dist-info/top_level.txt,sha256=U8Ogm0AUeUoKIgE9aENBcqtGIwn4H6Rs0j83ACUjBoA,6
9
+ ddata-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.45.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_commands]
2
+ my_command = my_package.my_module:main_function
3
+
@@ -0,0 +1 @@
1
+ ddata