feat(tools): 新增题目时自动生成带计时装饰器的模板文件

This commit is contained in:
2026-02-19 14:32:07 +08:00
parent f42b8e6461
commit 4dae9d2e78
2 changed files with 115 additions and 1 deletions

20
main.py
View File

@@ -15,7 +15,25 @@ def add_newproblem(num: int, name: str | None = None) -> None:
else:
title = f"{num:04d}"
Path(f"solutions/{title}").mkdir(parents=True, exist_ok=True)
Path(f"solutions/{title}/euler_{num}.py").touch()
file_name = f"solutions/{title}/euler_{num}.py"
Path(file_name).touch()
with open(file_name, "w") as f:
f.write("""'''
'''
import time
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"{func.__name__} time: {elapsed_time:.6f} seconds")
return result
return wrapper
""")
@app.command("list", help="List all problems in the projecteuler repository.")