# main.py
import utils
import tcpip
import ai_engine
import protocol_handler
import pprint # 이쁘게 출력
# 서버 정보
SERVER_IP = "10.10.20.111"
SERVER_PORT = 9000
def main():
print("🔌 서버 연결 시도 중...")
sock = tcpip.connect_to_server(SERVER_IP, SERVER_PORT)
if not sock:
print("❌ 서버 연결 실패. 종료합니다.")
return
try:
print("\n🚀 [1-0-0] 연결 요청")
result = protocol_handler.handle_1_0_0(sock)
print("📥 응답:", result)
print("\n📥 [1-0-1] 사용자 정보 수신")
user_num, meta = protocol_handler.handle_1_0_1(sock)
if user_num is None or not meta:
raise ValueError("❌ 수신된 사용자 정보가 유효하지 않습니다.")
print(f"👤 USER_NUM: {user_num}")
pprint.pprint(f"🧾 META: {meta}")
# ✅ AI 루틴 생성
# 출력없음: -1 / 전체출력: 0 / 원하는 주차 수 만큼: n
plan_dict = ai_engine.generate_routine(meta, debug_weeks=0)
if not plan_dict or "PLAN" not in plan_dict:
raise ValueError("❌ AI 응답이 유효하지 않습니다. JSON 형식 확인 필요.")
# ✅ CHECKLIST 생성 및 추가
week_plan = plan_dict["PLAN"].get("WEEK_PLAN", [])
days = plan_dict["PLAN"].get("DAYS", [])
plan_dict["CHECKLIST"] = utils.generate_checklist(week_plan, days)
print("✅ AI 루틴 생성 완료!")
print("\n📤 [1-0-2] AI 루틴 계획 전송")
result = protocol_handler.handle_1_0_2(sock, user_num, plan_dict)
print("📥 응답:", result)
except Exception as e:
print("❌ 처리 중 오류 발생:", e)
finally:
sock.close()
print("🔚 소켓 종료")
if __name__ == "__main__":
main()
################################################################################