Example #1
0
def get_events_from_ics(filepath, from_date, to_date):
    """Get events from an ics file
    """
    ics_file = open(filepath, 'r')
    cal = Calendar.from_ical(ics_file.read())
    projects = {}
    for event in cal.walk('vevent'):
        if from_date and to_date:
            if not within(event['DTSTART'].dt, from_date, to_date):
                continue
        name = str(event['SUMMARY']).lower()
        if '-' in name:
            project_name = name.split('-')[0].strip()
        else:
            project_name = name
        event_start = event['DTSTART'].dt
        event_end = event['DTEND'].dt
        project_total = calculate_time(event_start, event_end)
        if project_name in projects:
            new_total = projects[project_name]['total'] + project_total
            projects[project_name]['total'] = new_total
        else:
            projects[project_name] = {}
            projects[project_name]['total'] = project_total
    return projects
Example #2
0
 def test_within_edge(self):
     from_date = datetime(2014, 1, 1)
     to_date = datetime(2014, 6, 1)
     test_date = datetime(2014, 6, 1)
     value = within(test_date, from_date, to_date)
     self.assertEquals(value, False)