Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
112 lines (96 loc) · 2.97 KB
/
Copy pathapp.py
File metadata and controls
112 lines (96 loc) · 2.97 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from flask import Flask, render_template, request, redirect, url_for
import json
import os
from datetime import datetime, date
from typing import List, Dict, Optional
from pathlib import Path
app = Flask(__name__)
CONFIG_DIR = Path.home() / ".career_todo"
DATA_FILE = str(CONFIG_DIR / "todos.json")
CATEGORIES = ["자소서", "포폴", "면접", "기업분석", "AI활용", "기타"]
PRIORITIES = ["상", "중", "하"]
def today_str() -> str:
return date.today().isoformat()
def parse_date(s: str) -> Optional[str]:
s = s.strip()
if not s:
return None
try:
datetime.strptime(s, "%Y-%m-%d")
return s
except ValueError:
return None
def ensure_data_dir():
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
def load_todos() -> List[Dict]:
ensure_data_dir()
if not os.path.exists(DATA_FILE):
return []
try:
with open(DATA_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
if isinstance(data, list):
return data
return []
except Exception:
return []
def save_todos(todos: List[Dict]) -> None:
ensure_data_dir()
with open(DATA_FILE, "w", encoding="utf-8") as f:
json.dump(todos, f, ensure_ascii=False, indent=2)
def next_id(todos: List[Dict]) -> int:
if not todos:
return 1
return max(t.get("id", 0) for t in todos) + 1
@app.route('/')
def index():
todos = load_todos()
return render_template('index.html', todos=todos, categories=CATEGORIES, priorities=PRIORITIES)
@app.route('/add', methods=['POST'])
def add():
todos = load_todos()
title = request.form.get('title')
category = request.form.get('category')
priority = request.form.get('priority')
due_date = parse_date(request.form.get('due_date', ''))
if title:
todo = {
"id": next_id(todos),
"title": title,
"category": category,
"priority": priority,
"due_date": due_date,
"done": False,
"created_at": datetime.now().strftime("%Y-%m-%d %H:%M"),
"updated_at": None,
"notes": ""
}
todos.append(todo)
save_todos(todos)
return redirect(url_for('index'))
@app.route('/toggle/<int:todo_id>')
def toggle(todo_id):
todos = load_todos()
for t in todos:
if t['id'] == todo_id:
t['done'] = not t['done']
t['updated_at'] = datetime.now().strftime("%Y-%m-%d %H:%M")
break
save_todos(todos)
return redirect(url_for('index'))
@app.route('/delete/<int:todo_id>')
def delete(todo_id):
todos = load_todos()
todos = [t for t in todos if t['id'] != todo_id]
save_todos(todos)
return redirect(url_for('index'))
@app.route('/progress')
def progress():
todos = load_todos()
if not todos:
return "0"
done = sum(1 for t in todos if t.get("done"))
pct = round((done / len(todos)) * 100, 1)
return f"{pct}%"
if __name__ == '__main__':
app.run(debug=True)