jazzband / icalevents

Python module for iCal URL/file parsing and querying.
MIT License
157 stars 72 forks source link

showing deleted events #20

Open jc1518 opened 6 years ago

jc1518 commented 6 years ago

I wrote a script to get today's event from the team calendar on Confluence. The script downloads the ics file, then uses the icalevents to parse. I noticed that it shows the event that has been already deleted. The event is one instance of a recurring event.

Here is the script: https://github.com/jc1518/myscripts/blob/master/python-scripts/confluence/team_ics.py

jc1518 commented 5 years ago

Just did a big digging, I think the issue is that the module does not handle EXDATE.

jc1518 commented 5 years ago

I have added a quick fix in my local icalparser.py file (function parse_events), and it works for me so far. My code is not elegant though ;)

    for component in calendar.walk():
        i = 0
        if component.name == "VEVENT":
            if component.get('rrule'):
                if component.get('exdate'):
                    #print("----------------------------------------------")
                    #print(vDatetime(datetime.today()).to_ical())
                    if isinstance(component.get('exdate'), list):
                        for exdate in component.get('exdate'):
                            #print(str(exdate.to_ical()))
                            if str(exdate.to_ical()).replace("'", "") in str(vDatetime(datetime.today()).to_ical()).replace("'",""):
                                #print("+++++++++++++++++++++++++")
                                #print("Today is exception date")
                                #print(component)
                                i += 1
                    else:
                        #print(component.get('exdate').to_ical())
                        if str(component.get('exdate').to_ical()).replace("'", "") in str(vDatetime(datetime.today()).to_ical()).replace("'",""):
                            #print("+++++++++++++++++++++++++")
                            #print("Today is exception date")
                            #print(component)
                            i += 1
                if i == 0:
                    es = create_recurring_events(start, end, component)
                    if es:
                        found += es
            else:
                e = create_event(component)
                if e.end >= start and e.start <= end:
                    found.append(e)
    return found
`
PabloCastellano commented 5 years ago

Should be fixed in v0.1.8

@jc1518 can you check?

jc1518 commented 5 years ago

@PabloCastellano No, it does not fix it.

dlichtistw commented 5 years ago

Hm, that's odd, it worked for my EXDATEs... There is now even a unittest for EXDATE handling, which turns out positive. Could you recheck with v0.1.11, and maybe post some example ics code where EXDATE parsing fails?

jc1518 commented 5 years ago

@PabloCastellano , @dlichtistw, I think it is caused by that the tz is missed in the extract_exdates function.

It should be:

def extract_exdates(component, tz=UTC):
    """
    Compile a list of all exception dates stored with a component.

    :param component: icalendar iCal component
    :return: list of exception dates
    """
    dates = []

    exd_prop = component.get('exdate')
    if exd_prop:
        if isinstance(exd_prop, list):  # In case there is more than one exdate property
            for exd_list in exd_prop:
                dates.extend(normalize(exd.dt, tz=tz) for exd in exd_list.dts)
        elif isinstance(exd_prop, vDDDLists):
            dates.extend(normalize(exd.dt, tz=tz) for exd in exd_prop.dts)
    return dates