Spaces:
Running
Running
File size: 681 Bytes
186440e 7b8f88d 186440e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
import shutil
from datetime import datetime
from zoneinfo import ZoneInfo
from tzlocal import get_localzone
def timestamp(naive_time: datetime = None, target_tz=ZoneInfo("Asia/Shanghai")):
if not naive_time:
naive_time = datetime.now()
local_tz = get_localzone()
aware_local = naive_time.replace(tzinfo=local_tz)
return aware_local.astimezone(target_tz).strftime("%Y-%m-%d %H:%M:%S")
def mk_dir(dirpath: str):
if not os.path.exists(dirpath):
os.makedirs(dirpath)
def rm_dir(dirpath: str):
if os.path.exists(dirpath):
shutil.rmtree(dirpath)
def clean_dir(dirpath: str):
rm_dir(dirpath)
os.makedirs(dirpath)
|