working
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
def get_date() -> dict:
|
||||
_result = {}
|
||||
now = time.gmtime()
|
||||
_result["year"] = now.tm_year
|
||||
_result["month"] = now.tm_mon
|
||||
_result["day"] = now.tm_mday
|
||||
_result["hour"] = now.tm_hour
|
||||
_result["min"] = now.tm_min
|
||||
_result["sec"] = now.tm_sec
|
||||
|
||||
return _result
|
||||
|
||||
|
||||
def date_has_changed(d1: dict, d2: dict, fields=['year', 'month', 'day']):
|
||||
count = 0
|
||||
|
||||
try:
|
||||
for field in fields:
|
||||
if d1[field] != d2[field]:
|
||||
count += 1
|
||||
except KeyError:
|
||||
return True
|
||||
|
||||
return count > 0
|
||||
|
||||
|
||||
class FolderMgr:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def update(base_folder: str, _date: dict, fields=['year', 'month', 'day']) -> str:
|
||||
|
||||
appendix = ''
|
||||
for field in fields:
|
||||
appendix += f"{_date[field]}/"
|
||||
|
||||
folder = os.path.join(base_folder, appendix[:-1])
|
||||
try:
|
||||
os.makedirs(folder)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
return folder
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
date = get_date()
|
||||
print(date)
|
||||
mgr = FolderMgr()
|
||||
|
||||
for i in range(0, 10):
|
||||
folder = mgr.update("./", get_date(), fields=['year', 'month', 'day', 'hour', 'min', 'sec'])
|
||||
print(folder)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user