This commit is contained in:
2026-02-05 10:15:09 +03:00
parent 2427fce842
commit 67241a5ed0
33 changed files with 13147 additions and 154 deletions

View File

@@ -25,8 +25,8 @@ def load_schedule():
Returns a dictionary with day-wise schedule
"""
try:
# Read CSV file
df = pd.read_csv('schedule.csv')
# Read CSV file - Updated to use the provided file name
df = pd.read_csv('schedule_template RS.csv')
schedule = {}
# Process each row (each day)
@@ -34,20 +34,27 @@ def load_schedule():
day = row['Day']
schedule[day] = []
# Process each time slot column
time_slots = ['Period_1', 'Period_2', 'Period_3', 'Period_4', 'Period_5','Period_6', 'Period_7']
# Process each period column - Updated to match the actual CSV structure
# The CSV has columns labeled '1 (9:00-9:40)', '2 (10:00-10:40)', etc.
period_columns = [
'1 (9:00-9:40)', '2 (10:00-10:40)', '3 (11:00-11:40)', '4 (11:50-12:30)',
'5 (12:40-13:20)', '6 (13:30-14:10)', '7 (14:20-15:00)', '8 (15:20-16:00)',
'9 (16:15-16:55)', '10 (17:05-17:45)', '11 (17:55-18:35)', '12 (18:45-19:20)', '13 (19:20-20:00)'
]
for slot in time_slots:
# Check if class exists for this time slot
if pd.notna(row[slot]) and str(row[slot]).strip():
class_info = str(row[slot])
schedule[day].append((slot, class_info))
for i, col_name in enumerate(period_columns):
period_num = str(i + 1) # '1', '2', '3', etc.
# Check if the column exists and if class exists for this time slot
if col_name in row and pd.notna(row[col_name]) and str(row[col_name]).strip() != '':
class_info = str(row[col_name])
schedule[day].append((period_num, class_info)) # Store both period number and class info
return schedule
except FileNotFoundError:
print("❌ Error: schedule.csv file not found!")
print("Please create schedule.csv in the same folder")
print("❌ Error: schedule_template RS.csv file not found!")
print("Please make sure schedule_template RS.csv is in the same folder")
return {}
except Exception as e:
print(f"❌ Error loading schedule: {e}")
@@ -57,18 +64,26 @@ def load_schedule():
# Load schedule at startup
SCHEDULE = load_schedule()
# Time mapping for periods
PERIOD_TIMES = {
'Period_1': ('09:00', '09:40'),
'Period_2': ('10:00', '10:40'),
'Period_3': ('11:00', '11:40'),
'Period_4': ('11:50', '12:30'),
'Period_5': ('12:40', '13:20'),
'Period_6': ('13:30', '14:10'),
'Period_7': ('10:00', '10:40'),
# Map period numbers to times - Updated as requested
period_times = {
'1': ('09:00', '09:40'),
'2': ('10:00', '10:40'),
'3': ('11:00', '11:40'),
'4': ('11:50', '12:30'),
'5': ('12:40', '13:20'),
'6': ('13:30', '14:10'),
'7': ('14:20', '15:00'),
'8': ('15:20', '16:00'),
'9': ('16:15', '16:55'),
'10': ('17:05', '17:45'),
'11': ('17:55', '18:35'),
'12': ('18:45', '19:20'),
'13': ('19:20', '20:00')
}
# Time mapping for periods - Updated to use the new mapping
PERIOD_TIMES = period_times
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Send welcome message when command /start is issued."""
@@ -84,7 +99,7 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
async def where_am_i(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Tell user where they should be right now."""
if not SCHEDULE:
await update.message.reply_text("❌ Schedule not loaded. Check schedule.csv file.")
await update.message.reply_text("❌ Schedule not loaded. Check schedule_template RS.csv file.")
return
now = datetime.datetime.now()
@@ -101,9 +116,9 @@ async def where_am_i(update: Update, context: ContextTypes.DEFAULT_TYPE):
# Find current class
found_class = False
for period, class_info in SCHEDULE[current_day]:
start_time, end_time = PERIOD_TIMES[period]
for period_num, class_info in SCHEDULE[current_day]:
start_time, end_time = PERIOD_TIMES[period_num]
if start_time <= current_time <= end_time:
await update.message.reply_text(f"🎯 You should be in: {class_info}")
found_class = True
@@ -114,21 +129,25 @@ async def where_am_i(update: Update, context: ContextTypes.DEFAULT_TYPE):
async def schedule(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Show today's full schedule."""
"""Show the complete weekly schedule."""
if not SCHEDULE:
await update.message.reply_text("❌ Schedule not loaded. Check schedule.csv file.")
await update.message.reply_text("❌ Schedule not loaded. Check schedule_template RS.csv file.")
return
current_day = datetime.datetime.now().strftime("%A")
if current_day not in SCHEDULE or not SCHEDULE[current_day]:
await update.message.reply_text("😊 No classes scheduled for today!")
return
schedule_text = f"📚 {current_day}'s Schedule:\n\n"
for period, class_info in SCHEDULE[current_day]:
start, end = PERIOD_TIMES[period]
schedule_text += f"{start}-{end}: {class_info}\n"
schedule_text = "📚 Weekly Schedule:\n\n"
# Define the standard order of days in a week
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for day in days_of_week:
if day in SCHEDULE and SCHEDULE[day]: # Check if the day exists in the schedule and has classes
schedule_text += f"*{day}'s Schedule:*\n"
for period_num, class_info in SCHEDULE[day]:
start, end = PERIOD_TIMES[period_num]
schedule_text += f"{start}-{end}: {class_info}\n"
schedule_text += "\n"
else:
schedule_text += f"{day}: No classes scheduled\n\n"
await update.message.reply_text(schedule_text)
@@ -136,7 +155,7 @@ async def schedule(update: Update, context: ContextTypes.DEFAULT_TYPE):
async def tomorrow(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Show tomorrow's schedule."""
if not SCHEDULE:
await update.message.reply_text("❌ Schedule not loaded. Check schedule.csv file.")
await update.message.reply_text("❌ Schedule not loaded. Check schedule_template RS.csv file.")
return
tomorrow_date = datetime.datetime.now() + datetime.timedelta(days=1)
@@ -147,8 +166,8 @@ async def tomorrow(update: Update, context: ContextTypes.DEFAULT_TYPE):
return
schedule_text = f"📚 {tomorrow_day}'s Schedule:\n\n"
for period, class_info in SCHEDULE[tomorrow_day]:
start, end = PERIOD_TIMES[period]
for period_num, class_info in SCHEDULE[tomorrow_day]:
start, end = PERIOD_TIMES[period_num]
schedule_text += f"{start}-{end}: {class_info}\n"
await update.message.reply_text(schedule_text)
@@ -160,7 +179,7 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
"Available commands:\n"
"/start - Start the bot\n"
"/whereami - Find your current class\n"
"/schedule - Show today's schedule\n"
"/schedule - Show today's full schedule\n"
"/tomorrow - Show tomorrow's schedule\n"
"/help - Show this help message"
)
@@ -169,8 +188,8 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
def main():
"""Start the bot."""
if not SCHEDULE:
print("❌ Failed to load schedule. Please check schedule.csv file.")
print("Make sure schedule.csv exists in the same folder")
print("❌ Failed to load schedule. Please check schedule_template RS.csv file.")
print("Make sure schedule_template RS.csv exists in the same folder")
return
# Create the Application