pytbox 20250818.2__py3-none-any.whl → 20250818.4__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.

Potentially problematic release.


This version of pytbox might be problematic. Click here for more details.

pytbox/common/base.py CHANGED
@@ -1,44 +0,0 @@
1
- """
2
- Base classes and common utilities
3
- """
4
-
5
- from ..utils.timeutils import TimeUtils
6
- from typing import Dict, Any
7
- import json
8
-
9
-
10
- class BaseAPI:
11
- """API基类,提供通用功能"""
12
-
13
- def __init__(self, base_url: str = ""):
14
- self.base_url = base_url
15
- self._session_created_at = TimeUtils.get_timestamp()
16
-
17
- def get_session_age(self) -> int:
18
- """获取会话存活时间(秒)"""
19
- current_time = TimeUtils.get_timestamp()
20
- return current_time - self._session_created_at
21
-
22
- def log_request(self, method: str, url: str, data: Dict[Any, Any] = None) -> str:
23
- """记录请求日志"""
24
- timestamp = TimeUtils.get_timestamp()
25
- log_entry = {
26
- "timestamp": timestamp,
27
- "method": method,
28
- "url": url,
29
- "data": data or {}
30
- }
31
- return json.dumps(log_entry, ensure_ascii=False)
32
-
33
-
34
- class BaseResponse:
35
- """响应基类"""
36
-
37
- def __init__(self, data: Dict[Any, Any]):
38
- self.data = data
39
- self.created_at = TimeUtils.get_timestamp()
40
-
41
- def is_expired(self, ttl_seconds: int = 3600) -> bool:
42
- """检查响应是否过期"""
43
- current_time = TimeUtils.get_timestamp()
44
- return (current_time - self.created_at) > ttl_seconds
pytbox/utils/timeutils.py CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
 
4
4
  import time
5
+ import pytz
6
+ import datetime
5
7
 
6
8
 
7
9
  class TimeUtils:
@@ -20,4 +22,15 @@ class TimeUtils:
20
22
  if now:
21
23
  return int(time.time())
22
24
  else:
23
- return int(time.time() * 1000)
25
+ return int(time.time() * 1000)
26
+
27
+ @staticmethod
28
+ def get_time_object(now: bool=True):
29
+ '''
30
+ 获取当前时间, 加入了时区信息, 简单是存储在 Mongo 中时格式为 ISODate
31
+
32
+ Returns:
33
+ current_time(class): 时间, 格式: 2024-04-23 16:48:11.591589+08:00
34
+ '''
35
+ if now:
36
+ return datetime.datetime.now(pytz.timezone('Asia/Shanghai'))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytbox
3
- Version: 20250818.2
3
+ Version: 20250818.4
4
4
  Summary: A collection of Python integrations and utilities (Feishu, Dida365, VictoriaMetrics, ...)
5
5
  Author-email: mingming hou <houm01@foxmail.com>
6
6
  License: MIT
@@ -255,7 +255,7 @@ ruff check src/ tests/
255
255
  如有问题或建议,请通过以下方式联系:
256
256
 
257
257
  - 提交 [Issue](https://github.com/your-username/pytbox/issues)
258
- - 发送邮件至 you@example.com
258
+ - 发送邮件至 houm01@foxmail.com
259
259
 
260
260
  ---
261
261
 
@@ -0,0 +1,10 @@
1
+ pytbox/dida365.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ pytbox/victoriametrics.py,sha256=xYizUXeazVQM7-MT9wxhqtfol2fZrXjfrt1qRgDsTKU,1098
3
+ pytbox/common/__init__.py,sha256=3JWfgCQZKZuSH5NCE7OCzKwq82pkyop9l7sH5YSNyfU,122
4
+ pytbox/common/base.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pytbox/utils/response.py,sha256=WAsA84VDyOTEaFl2jyGFNhAiYuoI-UHngb89AiUXD_U,1251
6
+ pytbox/utils/timeutils.py,sha256=47nsdmfwQFe0UxGE41t05ayhtRDt8eOWXgN_3ZnqadQ,828
7
+ pytbox-20250818.4.dist-info/METADATA,sha256=2MowUunjhTZOJQR0zNEnXJ7LQ7wYb2zy3EzzrPJshkk,5929
8
+ pytbox-20250818.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ pytbox-20250818.4.dist-info/top_level.txt,sha256=YADgWue-Oe128ptN3J2hS3GB0Ncc5uZaSUM3e1rwswE,7
10
+ pytbox-20250818.4.dist-info/RECORD,,
pytbox/timeutils.py DELETED
@@ -1 +0,0 @@
1
-
@@ -1,11 +0,0 @@
1
- pytbox/dida365.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- pytbox/timeutils.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
3
- pytbox/victoriametrics.py,sha256=xYizUXeazVQM7-MT9wxhqtfol2fZrXjfrt1qRgDsTKU,1098
4
- pytbox/common/__init__.py,sha256=3JWfgCQZKZuSH5NCE7OCzKwq82pkyop9l7sH5YSNyfU,122
5
- pytbox/common/base.py,sha256=aMKLcBi0-3UEYxANolE_qInC-0ZeydMGBB803xWzorI,1291
6
- pytbox/utils/response.py,sha256=WAsA84VDyOTEaFl2jyGFNhAiYuoI-UHngb89AiUXD_U,1251
7
- pytbox/utils/timeutils.py,sha256=ebTowUmWPnv1i1YfOqJo8s1mti1gA7qonJ-qnv5S-ZE,423
8
- pytbox-20250818.2.dist-info/METADATA,sha256=3K7W__SsA8kgnFQVRuUPDVAq_biIuV_QikJVCb8y2sI,5926
9
- pytbox-20250818.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- pytbox-20250818.2.dist-info/top_level.txt,sha256=YADgWue-Oe128ptN3J2hS3GB0Ncc5uZaSUM3e1rwswE,7
11
- pytbox-20250818.2.dist-info/RECORD,,