pylhb 0.2.2__py3-none-any.whl → 0.2.5__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.
pylhb/myjson.py ADDED
@@ -0,0 +1,28 @@
1
+ """
2
+ 模块:myjson
3
+ 作者:李生
4
+ """
5
+ import json
6
+
7
+ # JSON读写
8
+ class MyJSON:
9
+ # 构造函数
10
+ def __init__(self,jsonFile="config.json") -> None:
11
+ self.jsonFile=jsonFile
12
+
13
+ # 获取Key
14
+ def getKey(self,key):
15
+ with open(self.jsonFile,'r', encoding="utf-8") as f:
16
+ configs=json.load(f)
17
+ return configs[key]
18
+
19
+ # 设置Key
20
+ def setKey(self,key,value):
21
+ # 读取
22
+ with open(self.jsonFile,'r', encoding="utf-8") as f:
23
+ configs=json.load(f)
24
+ # 设置参数
25
+ configs[key]=value
26
+ # 保存
27
+ with open(self.jsonFile, 'w', encoding="utf-8") as f:
28
+ json.dump(configs, f)
pylhb/mylog.py ADDED
@@ -0,0 +1,52 @@
1
+ """
2
+ 模块:mylog
3
+ 作者:李生
4
+ """
5
+ import os
6
+ from datetime import datetime
7
+ import inspect
8
+
9
+ # 日志处理类
10
+ class MyLog:
11
+ # 初始化
12
+ # 注意:保留天数(retainDays)必须在toLogFolder=True时才有效
13
+ def __init__(self, logType="Log", logFile='',toLogFolder=True,retainDays=30):
14
+ self.logType = logType
15
+ if len(self.logType)==0:
16
+ self.logType = "Log"
17
+ self.logFile= logFile
18
+ if len(self.logFile) == 0:
19
+ self.logFile=self.getTodayFileName()
20
+ self.toLogFolder = toLogFolder
21
+ self.retainDays = retainDays
22
+ if toLogFolder:
23
+ if not os.path.exists("Logs"):
24
+ os.makedirs("Logs")
25
+
26
+
27
+ # 获取今天的日志文件名
28
+ def getTodayFileName(self):
29
+ if self.toLogFolder:
30
+ return os.path.join("Logs", self.logType + "-" + datetime.now().strftime("%Y-%m-%d") + ".txt")
31
+ else:
32
+ return self.logType + "-" + datetime.now().strftime("%Y-%m-%d") + ".txt"
33
+
34
+ # 删除过期日志
35
+ def deleteExpiredLogs(self):
36
+ if self.toLogFolder:
37
+ logDir = "Logs"
38
+ if os.path.exists(logDir):
39
+ for filename in os.listdir(logDir):
40
+ filePath = os.path.join(logDir, filename)
41
+ if os.path.isfile(filePath):
42
+ fileDate = datetime.strptime(filename.split('-')[1].split('.')[0], "%Y-%m-%d")
43
+ if (datetime.now() - fileDate).days > self.retainDays:
44
+ os.remove(filePath)
45
+
46
+ # 添加日志
47
+ def add(self,log):
48
+ callFrame = inspect.currentframe().f_back
49
+ callInfo = inspect.getframeinfo(callFrame)
50
+ with open(self.logFile, 'a', encoding='utf-8') as file:
51
+ file.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] + " => " + f"{callInfo.filename} > {callInfo.function} > {callInfo.lineno}行" + ":" + log + "\n")
52
+
pylhb/myodbc.py CHANGED
@@ -38,7 +38,7 @@ class MSSQL:
38
38
  def connect(self) -> tuple[bool,str]:
39
39
  try:
40
40
  connectString = self.getConnectString()
41
- self.conn = pyodbc.connect(connectString)
41
+ self.conn = pyodbc.connect(connectString,autocommit=self.autoCommit)
42
42
  self.cursor=self.conn.cursor()
43
43
  return True,"OK"
44
44
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pylhb
3
- Version: 0.2.2
3
+ Version: 0.2.5
4
4
  Summary: Mr.Lee's Helpers
5
5
  License: Non-Commercial Use License
6
6
 
@@ -187,3 +187,27 @@ if __name__ == "__main__":
187
187
  # 关闭连接
188
188
  db.close()
189
189
  ```
190
+
191
+ ## 🌺mylog
192
+
193
+ 本地日志操作。
194
+
195
+ 使用示例:
196
+
197
+ ```
198
+ if __name__ == "__main__":
199
+ myLog= MyLog()
200
+ myLog.add("This is a test log entry.")
201
+ ```
202
+
203
+ ## 🌺myjson
204
+
205
+ json配置操作
206
+
207
+ 使用示例:
208
+
209
+ ```
210
+ if __name__ == "__main__":
211
+ appJson = MyJSON("config.json")
212
+ print(appJson.get("host"))
213
+ ```
@@ -0,0 +1,10 @@
1
+ pylhb/__init__.py,sha256=w-OXDD2tii5g0E0kWQYl-LP0C1LSezXFkUCe5cgO-nY,51
2
+ pylhb/myconfig.py,sha256=skaiIe2jfnWj4X3bfbBqBpygkcrDZ2rMKxX_CBKekms,1223
3
+ pylhb/myjson.py,sha256=tsk-xCeQaAhXB3r2UfHBnBKMOwju9gaeF6mHzKraRS8,713
4
+ pylhb/mylog.py,sha256=EQwJue0Vg_hl25kD4t5R9ZXGeJY5hvh_f-_R_-vPHFg,2029
5
+ pylhb/myodbc.py,sha256=2psoAiKLUHmw8M6oedOhQDg9-avVqMR1xX6pakibAgo,7748
6
+ pylhb/mysqlite.py,sha256=mXEiYoK-RIFC9PEq3Y2Sjq-dNcFGcIeQYSdrnP7Zv4Q,3593
7
+ pylhb-0.2.5.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
8
+ pylhb-0.2.5.dist-info/entry_points.txt,sha256=JgRWNHrbkaBFjPwbIi60UzpImMHwTtOchFnclGWMqeY,38
9
+ pylhb-0.2.5.dist-info/METADATA,sha256=YPECkfl9p3XSiJXOne1c59e-QxNgHNSFY3T4wk0I-AA,6341
10
+ pylhb-0.2.5.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.9.24
2
+ Generator: uv 0.9.28
3
3
  Root-Is-Purelib: true
4
- Tag: py3-none-any
4
+ Tag: py3-none-any
@@ -1,8 +0,0 @@
1
- pylhb/__init__.py,sha256=w-OXDD2tii5g0E0kWQYl-LP0C1LSezXFkUCe5cgO-nY,51
2
- pylhb/myconfig.py,sha256=skaiIe2jfnWj4X3bfbBqBpygkcrDZ2rMKxX_CBKekms,1223
3
- pylhb/myodbc.py,sha256=E5yiSSaN8_CtW40IeY_jJcgPlW3KBrZVN5t7UCh0RSQ,7721
4
- pylhb/mysqlite.py,sha256=mXEiYoK-RIFC9PEq3Y2Sjq-dNcFGcIeQYSdrnP7Zv4Q,3593
5
- pylhb-0.2.2.dist-info/WHEEL,sha256=eycQt0QpYmJMLKpE3X9iDk8R04v2ZF0x82ogq-zP6bQ,79
6
- pylhb-0.2.2.dist-info/entry_points.txt,sha256=JgRWNHrbkaBFjPwbIi60UzpImMHwTtOchFnclGWMqeY,38
7
- pylhb-0.2.2.dist-info/METADATA,sha256=qsRuLU3Qx0g_fIwSkiGei3CMqmfjxPUYBA30uUXgSrM,6036
8
- pylhb-0.2.2.dist-info/RECORD,,