| 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()) |
|
|