代码迁移
This commit is contained in:
0
etl_billiards/utils/__init__.py
Normal file
0
etl_billiards/utils/__init__.py
Normal file
22
etl_billiards/utils/helpers.py
Normal file
22
etl_billiards/utils/helpers.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""通用工具函数"""
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
def ensure_dir(path: Path):
|
||||
"""确保目录存在"""
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def make_surrogate_key(*parts) -> int:
|
||||
"""
|
||||
生成代理键
|
||||
将多个字段值拼接后计算SHA1,取前8字节转为无符号64位整数
|
||||
"""
|
||||
raw = "|".join("" if p is None else str(p) for p in parts)
|
||||
h = hashlib.sha1(raw.encode("utf-8")).digest()[:8]
|
||||
return int.from_bytes(h, byteorder="big", signed=False)
|
||||
|
||||
def now_local(tz) -> datetime:
|
||||
"""获取本地当前时间"""
|
||||
return datetime.now(tz)
|
||||
Reference in New Issue
Block a user