1

I need to calculate the days of the holidays rather than the term dates, but the calendar file (ics) is like this!

I need the results like this: Term 1 Start date = 2019-04-05 End date = 2019-04-23

So the end of term 1 is the start of the holidays and the start of term 2 is the end of the holiday. This also presents a problem for term 4 where the end of term 4 holiday is the start of term 1 for the next year.

Here is a sample of the calendar file

SUMMARY:Term 3 starts
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20190206T011107Z
UID:20190206T011107Z-1367275628@marudot.com
DTSTART;VALUE=DATE:20190920
DTEND;VALUE=DATE:20190920
SUMMARY:Term 3 ends
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20190206T011107Z
UID:20190206T011107Z-225094268@marudot.com
DTSTART;VALUE=DATE:20191007
DTEND;VALUE=DATE:20191007
SUMMARY:Term 4 starts
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20190206T011107Z
UID:20190206T011107Z-2103345721@marudot.com
DTSTART;VALUE=DATE:20191220
DTEND;VALUE=DATE:20191220
SUMMARY:Term 4 ends
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20190206T011107Z
UID:20190206T011107Z-507236695@marudot.com
DTSTART;VALUE=DATE:20200128
DTEND;VALUE=DATE:20200128
SUMMARY:Term 1 starts
DESCRIPTION:Students start 29 January in government schools
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20190206T011107Z
UID:20190206T011107Z-277640896@marudot.com
DTSTART;VALUE=DATE:20200327
DTEND;VALUE=DATE:20200327
SUMMARY:Term 1 ends
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20190206T011107Z
UID:20190206T011107Z-927611244@marudot.com
DTSTART;VALUE=DATE:20200414
DTEND;VALUE=DATE:20200414

from icalendar import Calendar, Event
g = open(VSH,'rb')
mycal = Calendar.from_ical(g.read())
for component in mycal.walk():
    if component.name == "VEVENT":
        mySummary = component.get('summary')

        if component.get('summary').find("starts") > 1:
            print(component.get('summary').replace("starts",""))
            print("we have a start event", component.get('dtstart').dt)
        elif component.get('summary').find("ends") > 1:
            print("we have a end event", component.get('dtend').dt)
g.close()
user2496011
  • 67
  • 3
  • 12
  • Possible duplicate of [Parsing files (ics/ icalendar) using Python](https://stackoverflow.com/questions/3408097/parsing-files-ics-icalendar-using-python) – wjandrea Apr 18 '19 at 01:04
  • If I've misunderstood your post, please [edit] to clarify. – wjandrea Apr 18 '19 at 01:06

0 Answers0