deepai / base /utils.py
zkneo's picture
1.pandas-ai.done
48d8f38
Raw
History Blame Contribute Delete
930 Bytes
import re
import uuid
import time
import hashlib
def camel_to_snake(name):
# 使用正则表达式匹配每个大写字母的前面(不包括首字符)
# 并在其前面插入下划线
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
# 再次使用正则表达式匹配单词的首字母大写,并在其前面添加下划线
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
def uuid_2_str():
return str(uuid.uuid4())
def ttl_hash(minutes=60):
"""Return the same value withing `seconds` time period"""
return round(time.time() / minutes / 60)
def sha256hex(path):
with open(path, "rb") as f:
data = f.read()
return hashlib.sha256(data).hexdigest()
__all__ = ["camel_to_snake", "uuid_2_str", "ttl_hash"]
if __name__ == "__main__":
print(0)
print(camel_to_snake("DataFile"))
print(uuid_2_str())
print(uuid.uuid4().hex)
print(ttl_hash())