Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. zane_shus
    Z
    • Continue chat with zane_shus
    • Start new chat with zane_shus
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    zane_shus

    @zane_shus

    0
    Reputation
    1
    Posts
    256
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    zane_shus Follow

    Posts made by zane_shus

    • 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"

      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.")
      posted in General
      Z
      zane_shus