Files
ai7-m3/ai_prompt.txt
2026-02-05 11:17:00 +03:00

218 lines
6.7 KiB
Plaintext

Based on your school scheduling system project, here's what the **API** would be:
## **API Architecture for Your School Scheduling System**
```python
# The API is the "Application Programming Interface" - it's how different parts
# of your system communicate with each other and with external applications
## **WHAT IS THE API IN YOUR PROJECT?**
In your project, the API serves as the **middle layer** between:
1. Your Telegram bot / Web interface
2. Your SQLite database
3. Future mobile apps or parent portals
## **API COMPONENTS:**
### **1. Database API Layer**
```python
# File: api/database.py
class DatabaseAPI:
"""API to interact with SQLite database"""
def get_student_schedule(self, student_id):
"""API method to get student schedule from database"""
# Connects to SQLite, runs query, returns JSON
pass
def find_student_location(self, student_name, time):
"""API to find where a student is at specific time"""
pass
def get_teacher_schedule(self, teacher_id):
"""API for teacher schedule queries"""
pass
```
### **2. Telegram Bot API Integration**
```python
# File: api/telegram_bot.py
class TelegramBotAPI:
"""API that connects Telegram bot commands to database"""
def handle_whereis_command(self, student_name):
"""When user types /whereis, this API method is called"""
# 1. Receive command from Telegram
# 2. Call DatabaseAPI.find_student_location()
# 3. Format response for Telegram
# 4. Send back to user
pass
def handle_schedule_command(self, student_name):
"""API for /schedule command"""
pass
```
### **3. Web API (REST API)**
```python
# File: api/web_api.py
# This would be built with Flask or FastAPI
# Example API endpoints:
# GET /api/students/{id}/schedule - Get student schedule
# GET /api/teachers/{id}/classes - Get teacher classes
# GET /api/rooms/availability - Check room availability
# POST /api/schedule/update - Update schedule (admin)
```
## **HOW THE API WORKS IN YOUR SYSTEM:**
```
User Types: /whereis София
Telegram Bot (Frontend)
Calls: TelegramBotAPI.handle_whereis_command("София")
Calls: DatabaseAPI.find_student_location("София", current_time)
Executes SQL query on school_schedule.db
Returns: {"student": "София", "room": "204", "subject": "Design"}
Formats for Telegram: "София: Room 204, Design & Creativity"
Sends to user
```
## **API ENDPOINTS IN YOUR PROJECT:**
### **For Telegram Bot:**
```
Internal API Methods:
- find_student(current_time, student_name) → returns location
- get_daily_schedule(student_id, date) → returns schedule
- get_teacher_schedule(teacher_id) → returns teacher classes
- check_room_availability(room_id, time_slot) → returns boolean
```
### **For Future Web Portal (REST API):**
```http
# Student endpoints
GET /api/v1/students # List all students
GET /api/v1/students/{id} # Get student details
GET /api/v1/students/{id}/schedule # Get student schedule
GET /api/v1/students/{id}/location # Get current location
# Teacher endpoints
GET /api/v1/teachers/{id}/schedule # Get teacher schedule
GET /api/v1/teachers/{id}/students # Get teacher's students
# Schedule endpoints
GET /api/v1/schedule/day/{date} # Daily schedule
GET /api/v1/schedule/room/{id} # Room schedule
POST /api/v1/schedule # Create schedule entry
PUT /api/v1/schedule/{id} # Update schedule
# Room endpoints
GET /api/v1/rooms # List all rooms
GET /api/v1/rooms/{id}/availability # Check room availability
```
## **API IN YOUR TECHNOLOGY STACK:**
```python
# Your actual implementation (from your presentation):
# Telegram Bot → Python → SQLite Database
# ↑ ↑
# API Calls API Layer
# File: bot_api.py (simplified version of what you have)
import sqlite3
from datetime import datetime
class SchoolSchedulerAPI:
def __init__(self, db_path="school_schedule.db"):
self.db_path = db_path
self.connection = sqlite3.connect(db_path)
def api_whereis_student(self, student_name):
"""API method called by Telegram bot"""
query = """
SELECT s.name, r.room_number, sub.subject_name, t.name as teacher
FROM students s
JOIN schedule_entries se ON s.student_id = se.student_id
JOIN rooms r ON se.room_id = r.room_id
JOIN subjects sub ON se.subject_id = sub.subject_id
JOIN teachers t ON se.teacher_id = t.teacher_id
WHERE s.name = ? AND se.time_slot = ?
"""
current_time = datetime.now().strftime("%H:%M")
result = self.connection.execute(query, (student_name, current_time)).fetchone()
# API Response format
if result:
return {
"success": True,
"student": result[0],
"room": result[1],
"subject": result[2],
"teacher": result[3],
"time": current_time
}
else:
return {"success": False, "message": "Student not found"}
def api_get_schedule(self, student_name, date=None):
"""API to get full schedule"""
# Implementation similar to above
pass
```
## **WHY YOU NEED AN API:**
1. **Separation of Concerns**: Database logic separate from bot logic
2. **Reusability**: Same API can be used by:
- Telegram Bot
- Web Portal
- Mobile App
- Parent Dashboard
3. **Maintainability**: Change database without breaking bot
4. **Scalability**: Can add caching, load balancing
5. **Security**: Centralized authentication and validation
## **API IN YOUR FUTURE DEVELOPMENT:**
From your Slide 9 (Future Development):
```
Student/Parent portal → Needs API
Staff portal → Needs API
AI suggestions → Uses API to get data
Analytics → Uses API to query database
```
## **SUMMARY:**
Your **API** is:
1. **The bridge** between Telegram bot and SQLite database
2. **A set of methods/functions** that handle specific requests
3. **The business logic layer** that processes data
4. **Future-ready** for web/mobile applications
5. **Implemented in Python** using functions/classes that interface with sqlite3
**Current API Flow:**
```
User → Telegram → Your Python Code (API) → SQLite → Response → User
```
**Future API Flow:**
```
Mobile App → HTTP Request → Web API (Flask/FastAPI) → SQLite → JSON Response → Mobile App
Parent Portal → Same API → Same Database
```
The API is what makes your system "intelligent" and accessible from multiple interfaces while keeping the database operations centralized and secure.