🤖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

    Scheduled Pinned Locked Moved General
    2 Posts 2 Posters 2.3k Views 1 Watching
    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 Offline
      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 Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post