Harupi 9 месяцев назад
Родитель
Сommit
61f0adeaa8
2 измененных файлов с 32 добавлено и 2 удалено
  1. 6 2
      main.py
  2. 26 0
      today.py

+ 6 - 2
main.py

@@ -1,5 +1,5 @@
 import discord
-from today import today
+from today import today, tomorrow
 
 # Creating a client instance
 intents = discord.Intents.default()
@@ -19,5 +19,9 @@ async def on_message(message):
     if message.content.startswith("edt?"):      # Check if the message starts with 'edt', which is the command we defined to view the timetable.
         await message.channel.send(today())
 
-client.run("PUT YOUR TOKEN HERE")
+    if message.content.startswith("demain?"):
+        await message.channel.send(tomorrow())
+
+
+client.run("MTQxMTEwNTIxNzkzOTkwMjY4NQ.GZ7ZQZ.tiLRAw5wRCiWnIosNZnATT7wy4i_wU2OiHSgTk")
 

+ 26 - 0
today.py

@@ -30,3 +30,29 @@ def today():
     
     return msg
 
+def tomorrow():
+    """Returns a string containing all events for the day, their location and their time"""
+    cal_path = Path("data/cal.ics")                                     # Rename your calendar in cal.ics and put in in a folder called data (or just change the path)
+    cal = icalendar.Calendar.from_ical(cal_path.read_bytes())
+    today = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Paris"))    # The date of today, in the Paris timezone, choose whichever you want
+    
+
+    attends_tab = []
+
+    for event in cal.events:
+        if event.get("DTSTART").dt.day - 1 == today.day and event.get("DTSTART").dt.month == today.month :        # Check every event in the calendar and execute the code if their are today
+            event_desc = "\n"+"### "+event.get("SUMMARY")+" ###"
+
+            event_desc += "\n"+event.get("LOCATION")
+
+            event_desc += "\n"+"<t:"+str(round(event.get("DTSTART").dt.timestamp()))+":t> - <t:"+str(round(event.get("DTEND").dt.timestamp()))+":t>"    # Convert the date in vDDDType to a discord timestamp
+            
+            attends_tab.append((event_desc,event.get("DTSTART").dt.timestamp()))
+    
+    attends_tab_sorted = sorted(attends_tab, key= lambda x: x[1])   # Order every eent of today by ascending timestamp
+
+    msg = "Voici l'emploi du temps du jour :\n"
+    for event in attends_tab_sorted:        # Add all events to the message
+        msg += event[0]
+    
+    return msg