# Fix import of timedelta
from datetime import timedelta

# Redefining the ics creation process

# Menu details for each day
menu_details = {
    "Monday": {
        "Breakfast": "Aloo onion paratha, Chutney, Curd, Fruits/Eggs, Daliya, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "Arhar Dal, Veg Kofta, Rice, Roti, Green Salad, Lemon + Pickle",
        "Snacks": "Macaroni/Pasta, Coffee",
        "Dinner": "Rajasthani Sev Tamatar, Dal Fry, Roti, Rice, Green Salad, Pickle, Motichur Laddu"
    },
    "Tuesday": {
        "Breakfast": "Puri, Chana Masala, Halwa, Fruits/Omlette, Cornflakes, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "Moong Dal, Mix Veg, Roti, Jeera Rice, Green Salad, Lemon + Pickle",
        "Snacks": "Pav Bhaji, Tea",
        "Dinner": "Aloo Jeera + Soup, Dal Tadka, Roti, Rice, Green Salad, Pickle, Rasgulla"
    },
    "Wednesday": {
        "Breakfast": "Mix Paratha, Dhaniya Chutney, Curd, 2 Bananas/Eggs, Daliya, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "Kadhi Pakora, Kaddu Khatta, Roti, Rice, Green Salad, Lemon + Pickle",
        "Snacks": "Veg Sandwich, Tea",
        "Dinner": "Kadahi Paneer/Chicken Curry, Red Massor Dal, Roti, Rice, Green Salad, Pickle, Fruit Custard"
    },
    "Thursday": {
        "Breakfast": "Poha, Green Chutney, Coconut Chutney, Fruits/2 Eggs, Daliya, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "White Chole, Aloo Began Bhartha, Roti, Rice, Green Salad, Lemon + Pickle",
        "Snacks": "Fried Idli, Tea",
        "Dinner": "Mix Veg (Gajar+Paneer/Mushroom+Beans+Gobi+Matar), Dal Makhni, Roti, Rice, Green Salad, Pickle, Gulab Jamun"
    },
    "Friday": {
        "Breakfast": "Idli, Sambhar & Chutney, Coconut Chutney, Fruits/2 Eggs, Cornflakes, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "Rajma, Aloo Tamatar Sabji, Roti, Jeera Rice, Bundi Raita, Green Salad, Lemon + Pickle",
        "Snacks": "Chana Peanut Chat, Tea",
        "Dinner": "Paneer Butter Masala/Egg Curry, Mix Dal, Roti, Rice, Green Salad, Pickle, Besan Burfi"
    },
    "Saturday": {
        "Breakfast": "Methi/Palak Paratha, Curd, Coconut Chutney, Fruits/2 Eggs, Cornflakes, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "Paneer Bhurji, Chana Dal, Poori, Rice, Green Salad, Lemon + Pickle",
        "Snacks": "Samosa+Imli Chat, Tea",
        "Dinner": "Paneer Biryani/Chicken Biryani, Dal Fry, Roti, Raita, Ice Cream"
    },
    "Sunday": {
        "Breakfast": "Masala Onion Dosa, Sambar, Coconut Chutney, Fruits/2 Eggs, Daliya, Milk, Bread, Butter, Jam, Bournvita, Coffee/Tea, Sprouts",
        "Lunch": "Egg Bhurji, Chole, Fried Masala Chilli, Roti, Khichdi, Curd, Green Salad, Lemon + Pickle",
        "Snacks": "Bhel Poori, Coffee",
        "Dinner": "Aloo Soyabean, Dal Fry, Roti, Rice, Green Salad, Pickle, Kheer"
    }
}

# Days of the week mapping
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

# Adding events to the calendar
for i, day in enumerate(days_of_week):
    meals = menu_details[day]
    day_offset = timedelta(days=i)  # To set correct day of the week
    current_day = (datetime.now(tz) + day_offset).replace(hour=0, minute=0, second=0, microsecond=0)
    
    for meal, time_info in [("Breakfast", ("07:00", "09:30") if i < 5 else ("07:30", "10:00")),
                            ("Lunch", ("12:00", "14:00")),
                            ("Snacks", ("17:00", "18:00")),
                            ("Dinner", ("19:30", "21:30"))]:
        # Event for meal
        event = Event()
        start_time = datetime.strptime(time_info[0], "%H:%M").time()
        end_time = datetime.strptime(time_info[1], "%H:%M").time()
        event.add('summary', f"{meal} - {meals[meal]}")
        event.add('dtstart', tz.localize(datetime.combine(current_day, start_time)))
        event.add('dtend', tz.localize(datetime.combine(current_day, end_time)))
        event.add('rrule', {'freq': 'weekly'})
        cal.add_component(event)

# Save to .ics file
ics_filename = "/mnt/data/weekly_mess_menu.ics"
with open(ics_filename, 'wb') as f:
    f.write(cal.to_ical())

ics_filename

fix this code