前言
内容
import calendar
import os
# run demo for lib use
def run_demo():
week, days = calendar.monthrange(2022, 10)
print(f"week:{week} days:{days}")
def gen_folder(start: int, end: int, proc) -> None:
"""
gen folder before years
"""
for year in range(start, end+1):
for mon in range(1, 13):
print("year({})mon({})".format(year, mon))
proc(year, mon)
pass
def create_proc(year: int, mon: int):
"""
create folder accorrding to year and mon
"""
week, days = calendar.monthrange(year=year, month=mon)
for d in range(1, days):
folder = os.path.join(os.getcwd(),
"{:04d}/{:02d}/{:02d}".format(year, mon, d))
if os.path.exists(folder):
print("path({}) exist".format(folder))
continue
print("create folder({})".format(folder))
os.makedirs(folder)
if __name__ == "__main__":
gen_folder(2020, 2024, create_proc)
格式控制图片