import time
import json
import random
# ==================================================
# DISPLAY PLACEHOLDER (TFT / Serial)
# ==================================================
def clear():
print("\n" * 6)
def show(text):
print(text)
# ==================================================
# STORAGE
# ==================================================
FILE = "students.json"
def load_data():
try:
with open(FILE, "r") as f:
return json.load(f)
except:
return {}
def save_data(data):
with open(FILE, "w") as f:
json.dump(data, f)
# ==================================================
# MOTIVATION QUOTES
# ==================================================
LOCAL_QUOTES = [
"Focus builds the future.",
"Small focus, big success.",
"Discipline beats motivation.",
"One task at a time."
]
# ==================================================
# LOGIN (BUTTON CONFIRM LATER)
# ==================================================
def login():
data = load_data()
clear()
show("SMART STUDY TABLE")
show("------------------")
student_id = input("Student ID: ")
if student_id not in data:
data[student_id] = {"tasks": []}
save_data(data)
show("New profile created")
show("Login OK")
time.sleep(1)
return student_id
# ==================================================
# TASK MENU (BUTTON BASED)
# ==================================================
def tasks_menu(student_id):
data = load_data()
tasks = data[student_id]["tasks"]
while True:
clear()
show("TASK LIST")
if not tasks:
show("No tasks")
for i, task in enumerate(tasks):
status = "DONE" if task["done"] else "PENDING"
show(f"{i+1}. {status} - {task['text']}")
show("------------------")
show("1:Add")
show("2:Toggle")
show("3:Back")
btn = input("Button: ")
if btn == "1":
text = input("Task: ")
tasks.append({"text": text, "done": False})
save_data(data)
elif btn == "2":
num = int(input("Task No: ")) - 1
if 0 <= num < len(tasks):
tasks[num]["done"] = not tasks[num]["done"]
save_data(data)
elif btn == "3":
break
# ==================================================
# STUDY TIMER (NO TOUCH, NO BLOCKING INPUT BUG)
# ==================================================
def study_timer():
clear()
minutes = int(input("Minutes: "))
total = minutes * 60
remaining = total
paused = False
while remaining > 0:
clear()
m = remaining // 60
s = remaining % 60
show(f"TIMER {m:02d}:{s:02d}")
show("1:Pause 2:Reset 3:Exit")
time.sleep(1)
if not paused:
remaining -= 1
if remaining % 5 == 0:
btn = input("Button: ")
if btn == "1":
paused = not paused
elif btn == "2":
remaining = total
paused = False
elif btn == "3":
return
show("SESSION COMPLETE")
time.sleep(2)
# ==================================================
# STATUS SCREEN (SENSOR PLACEHOLDER)
# ==================================================
def status_screen():
clear()
posture = random.choice(["GOOD", "BAD"])
focus = random.choice(["GOOD", "BAD"])
show(f"POSTURE: {posture}")
show("------------------")
if focus == "BAD":
show("FOCUS: LOW")
show(random.choice(LOCAL_QUOTES))
else:
show("FOCUS: GOOD")
time.sleep(3)
# ==================================================
# HOME MENU (BUTTON ONLY)
# ==================================================
def home(student_id):
while True:
clear()
show(f"STUDENT: {student_id}")
show("------------------")
show("1:Tasks")
show("2:Study Timer")
show("3:Status")
show("4:Logout")
btn = input("Button: ")
if btn == "1":
tasks_menu(student_id)
elif btn == "2":
study_timer()
elif btn == "3":
status_screen()
elif btn == "4":
break
# ==================================================
# MAIN LOOP
# ==================================================
while True:
user = login()
home(user)