🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Python Module when using Blocky

    General
    2
    2
    1.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zane_shus
      last edited by

      I am trying to use the FLow/Blocky interface to read a remote ICS file. It needs a python module. How do I do this please? I get a error "no module names icalendar"

      import urequests
      from icalendar import Calendar
      from datetime import datetime
      
      def download_file(url):
          headers = {
              'User-Agent': 'MicroPython'
          }
          response = urequests.get(url, headers=headers)
          if response.status_code == 200:
              file_contents = response.content
              return file_contents
          else:
              return None
      
      def parse_ics(ics_data):
          calendar = Calendar.from_ical(ics_data)
          current_meeting = None
          next_meeting = None
          now = datetime.now()
      
          for event in calendar.walk('vevent'):
              start_time = event.get('dtstart').dt
              end_time = event.get('dtend').dt
              if start_time <= now <= end_time:
                  current_meeting = event.get('summary')
              elif start_time > now:
                  if next_meeting is None or start_time < next_meeting['start']:
                      next_meeting = {
                          'start': start_time,
                          'summary': event.get('summary')
                      }
      
          return current_meeting, next_meeting
      
      # Example usage
      ics_url = "http://example.com/meetings.ics"
      ics_data = download_file(ics_url)
      if ics_data is not None:
          current_meeting, next_meeting = parse_ics(ics_data)
          if current_meeting:
              print("Current meeting:", current_meeting)
          else:
              print("FREETIME")
          
          if next_meeting:
              time_until_next = (next_meeting['start'] - datetime.now()).total_seconds()
              print("Next meeting:", next_meeting['summary'])
              print("Seconds until next meeting:", time_until_next)
      else:
          print("Failed to download the ICS file.")
      1 Reply Last reply Reply Quote 0
      • Z
        zabrodskyitaras
        last edited by

        @zane_shus said in Python Module when using Blocky:

        I am trying to use the FLow/Blocky interface to read a remote ICS file. It needs a python module. How do I do this please? I get a error "no module names icalendar"

        It seems like you're encountering an issue with the "icalendar" Python module while trying to use the Flow/Blocky interface to read a remote ICS file. The error message "no module named icalendar" indicates that the required Python module is not installed in your environment.

        1 Reply Last reply Reply Quote 1
        • First post
          Last post