Initial Commit
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python
|
||||
"""작업하면서 남긴 작은 스텝을 날짜별 MD 표로 쌓는다.
|
||||
|
||||
커밋(작업 묶음)보다 작은 단위 로그다. 스텝을 그때그때 한 줄씩 append.
|
||||
|
||||
한 파일로 끝: work-log/YYYY-MM/YYYY-MM-DD.md
|
||||
헤더(제목 + 표 헤더) 없으면 만들고, 스텝을 표 행(| 시간 | 내용 |)으로 파일 끝에 붙인다.
|
||||
MD 라 에디터·GitHub 어디서나 표로 바로 보임 — 따로 렌더/생성 단계 없음(그래서 멱등 걱정도 없음).
|
||||
|
||||
사용법:
|
||||
python gen_worklog.py add "끊김 재현 테스트부터 짜서 버그 재현함"
|
||||
→ 지금 시각 찍어 오늘 md 에 표 행 append (파일 없으면 헤더까지 만들고)
|
||||
python gen_worklog.py --selftest → 자체검증
|
||||
"""
|
||||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
OUT = Path(__file__).resolve().parent
|
||||
WEEKDAY = ["월", "화", "수", "목", "금", "토", "일"]
|
||||
|
||||
|
||||
def today():
|
||||
return datetime.now().astimezone().strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def now_hm():
|
||||
return datetime.now().astimezone().strftime("%H:%M")
|
||||
|
||||
|
||||
def md_path(date):
|
||||
return OUT / date[:7] / f"{date}.md" # 월별 폴더(YYYY-MM) 아래에 쌓음
|
||||
|
||||
|
||||
def header(date):
|
||||
d = datetime.strptime(date, "%Y-%m-%d")
|
||||
return f"# 작업로그 · {date} ({WEEKDAY[d.weekday()]})\n\n| 시간 | 내용 |\n|------|------|\n"
|
||||
|
||||
|
||||
def cell(text):
|
||||
"""표 한 칸용: 줄바꿈·탭은 공백으로, 파이프는 이스케이프(표 안 깨지게)."""
|
||||
return " ".join(text.split()).replace("|", "\\|")
|
||||
|
||||
|
||||
def add_step(text):
|
||||
"""오늘 md 표에 '| HH:MM | 내용 |' 한 줄 append. 헤더 없으면 먼저 만든다."""
|
||||
text = cell(text)
|
||||
if not text:
|
||||
return
|
||||
p = md_path(today())
|
||||
p.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not p.exists():
|
||||
p.write_text(header(today()), encoding="utf-8")
|
||||
with p.open("a", encoding="utf-8") as f:
|
||||
f.write(f"| {now_hm()} | {text} |\n")
|
||||
|
||||
|
||||
def selftest():
|
||||
import tempfile
|
||||
|
||||
global OUT
|
||||
orig = OUT
|
||||
OUT = Path(tempfile.mkdtemp())
|
||||
try:
|
||||
add_step(" 첫 번째\t스텝 ") # 탭·공백 정리 확인
|
||||
add_step("파이프 | 든 스텝") # 표 깨짐 방지 이스케이프 확인
|
||||
txt = md_path(today()).read_text(encoding="utf-8")
|
||||
assert txt.startswith("# 작업로그"), txt
|
||||
assert "| 시간 | 내용 |" in txt
|
||||
assert "| 첫 번째 스텝 |" in txt
|
||||
assert "파이프 \\| 든 스텝" in txt
|
||||
assert txt.rstrip().count("\n") == 5 # 제목 + 빈줄 + 헤더2행 + 스텝2행
|
||||
print("selftest ok")
|
||||
finally:
|
||||
OUT = orig
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if args and args[0] == "--selftest":
|
||||
selftest()
|
||||
elif args and args[0] == "add":
|
||||
add_step(" ".join(args[1:]))
|
||||
else:
|
||||
print('usage: gen_worklog.py add "<한 일 한 줄>" | --selftest')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user