def test_include(): results = list( filter.by_date_range( event_generator(), datetime.datetime(2008, 3, 13, tzinfo=utc), datetime.datetime(2008, 3, 15, tzinfo=utc), )) assert len(results) == 1, results
def test_exclude(): results = list( filter.by_date_range( event_generator(), datetime.datetime(2009, 3, 21, tzinfo=utc), datetime.datetime(2009, 3, 21, tzinfo=utc), )) assert len(results) == 0, results
def test_filter_several_days(): results = list( filter.by_date_range( calendar.vevent_list, datetime.datetime(2009, 11, 1, tzinfo=local), datetime.datetime(2009, 11, 30, tzinfo=local), )) assert len(results) == 1, len(results) assert results[0].summary.value == 'present', results[0].summary.value return
def test_filter_one_day(): results = list( filter.by_date_range( calendar.vevent_list, datetime.datetime(2009, 11, 26, tzinfo=local), datetime.datetime(2009, 11, 27, tzinfo=local), )) summaries = [r.summary.value for r in results] assert summaries == ['weekly', 'daily'], summaries return
def test_filter_dst_event_out_of_dst(): components = list(vobject.readComponents(CALENDAR_DATA)) events = components[0].vevent_list results = list( filter.by_date_range( events, datetime.datetime(2010, 3, 20, tzinfo=utc), datetime.datetime(2010, 3, 28, tzinfo=utc), )) assert len(results) == 1 return
def test_filter_several_days(): results = list( filter.by_date_range( calendar.vevent_list, datetime.datetime(2009, 11, 1, tzinfo=local), datetime.datetime(2009, 11, 30, tzinfo=local), )) summaries = [(r.summary.value, r.dtstart.value) for r in results] print summaries assert summaries == [ ('weekly', datetime.datetime(2009, 11, 26, 13, 0, tzinfo=local)), ('daily', datetime.datetime(2009, 11, 26, 13, 0, tzinfo=local)), ('daily', datetime.datetime(2009, 11, 27, 13, 0, tzinfo=local)), ('daily', datetime.datetime(2009, 11, 28, 13, 0, tzinfo=local)), ('daily', datetime.datetime(2009, 11, 29, 13, 0, tzinfo=local)), ] return
def test_one_day(): # See issue #2 c = vobject.iCalendar() calendar = c # VEVENT # DTSTAMP: 2007-09-24 06:51:23+00:00 # UID: EF86F13E-2130-42F5-8809-D37251BB7B7D # SEQUENCE: 5 # CREATED: 2009-02-14 17:04:06+00:00 # TRANSP: OPAQUE # SUMMARY: Marcel vrij # EXDATE: [datetime.date(2009, 3, 27)] # params for EXDATE: # VALUE [u'DATE'] # EXDATE: [datetime.date(2009, 3, 20)] # params for EXDATE: # VALUE [u'DATE'] # DTEND: 2007-09-21 # params for DTEND: # VALUE [u'DATE'] # DTSTART: 2007-09-21 # params for DTSTART: # VALUE [u'DATE'] # RRULE: FREQ=WEEKLY;INTERVAL=1 e = c.add('vevent') e.add('summary').value = "Marcel vrij" start = e.add('dtstart') start.value = datetime.date(2007, 9, 21) end = e.add('dtend') end.value = datetime.date(2007, 9, 22) results = list(filter.by_date_range( calendar.vevent_list, datetime.datetime(2007, 9, 19, tzinfo = local), datetime.datetime(2007, 9, 23, tzinfo = local), )) event = results[0] print 'START:', event.dtstart.value print 'END :', event.dtend.value assert event.dtstart.value == datetime.date(2007, 9, 21) assert event.dtend.value == datetime.date(2007, 9, 22) return
def main(args=sys.argv[1:]): option_parser = optparse.OptionParser( usage='usage: ical2org [options] [calendar titles]', conflict_handler='resolve', description='Convert iCal calendar entries to org-mode data for use with emacs', ) option_parser.add_option('-c', '--config', action='store', dest='config_filename', help='Configuration file name. Defaults to ~/.ical2org', default=os.path.expanduser('~/.ical2org'), ) option_parser.add_option('--begin', '-b', '--days-ago', action='store', dest='days_ago', help='Number of days back in time to search. Defaults to 14.', default=14, type=int, ) option_parser.add_option('--end', '-e', '--days-ahead', action='store', dest='days_ahead', help='Number of days forward in time to search. Defaults to 30.', default=30, type=int, ) option_parser.add_option('-v', '--verbose', action='count', dest='verbose_level', default=1, help='Increase verbose level', ) option_parser.add_option('-q', '--quiet', action='store_const', const=0, dest='verbose_level', help='Turn off verbose output', ) option_parser.add_option('--output-file', '-o', action='store', dest='output_file_name', help='Write the output to the named file instead of stdout', default=None, ) option_parser.add_option('--all', action='store_false', dest='active_only', default=True, help='Include all calendars, not just active.', ) option_parser.add_option('--input-directory', action='store', dest='input_directory', default=os.path.expanduser('~/Library/Calendars'), help='Directory containing calendars. Defaults to ~/Library/Calendars.', ) option_parser.add_option('--format', '-f', action='store', dest='format', type='choice', choices=FORMATTER_FACTORIES.keys(), default='org', help='Output format. One of %s. Defaults to "diary".' % FORMATTER_FACTORIES.keys(), ) option_parser.add_option('--opt', '--formatter-option', action='callback', type='string', callback=remember_formatter_option, help='Formatter-specific option name=value', ) option_parser.add_option('--help', action='callback', callback=show_verbose_help, help='Verbose help', ) options, calendar_titles = option_parser.parse_args(args) log_level = VERBOSE_LEVELS.get(options.verbose_level, logging.DEBUG) logging.basicConfig(level=log_level, format='%(message)s') config = ConfigParser() config.read([options.config_filename]) # Compute the date range for items to be included in our output. start_date = tz.normalize_to_utc(datetime.datetime.combine( datetime.date.today() - datetime.timedelta(options.days_ago), datetime.time.min, )) end_date = tz.normalize_to_utc(datetime.datetime.combine( datetime.date.today() + datetime.timedelta(options.days_ahead + 1), datetime.time.min, )) logging.info('Starting %d days ago at %s', options.days_ago, start_date.astimezone(tz.local)) logging.info('Ending %d days from now at %s', options.days_ahead, end_date.astimezone(tz.local)) if options.output_file_name: logging.info('Writing to %s', options.output_file_name) # Load the calendars if calendar_titles: calendar_generator = calendars.get_by_titles(path=options.input_directory, titles=calendar_titles) else: calendar_generator = calendars.discover(path=options.input_directory, active_only=options.active_only) # Process the calendar data output = sys.stdout if options.output_file_name: output = codecs.open(options.output_file_name, 'wt', 'UTF-8') try: formatter = FORMATTER_FACTORIES[options.format](output, config, options) for calendar in calendar_generator: logging.info('Processing: %s', calendar.title) formatter.start_calendar(calendar) for event in filter.unique(filter.by_date_range(calendar.get_events(), start_date, end_date, )): logging.info(' %s', event.summary.value) formatter.add_event(event) formatter.end_calendar(calendar) finally: formatter.close() if output != sys.stdout: output.close() return
def main(args=sys.argv[1:]): option_parser = optparse.OptionParser( usage='usage: ical2org [options] [calendar titles]', conflict_handler='resolve', description= 'Convert iCal calendar entries to org-mode data for use with emacs', ) option_parser.add_option( '-c', '--config', action='store', dest='config_filename', help='Configuration file name. Defaults to ~/.ical2org', default=os.path.expanduser('~/.ical2org'), ) option_parser.add_option( '--begin', '-b', '--days-ago', action='store', dest='days_ago', help='Number of days back in time to search. Defaults to 14.', default=14, type=int, ) option_parser.add_option( '--end', '-e', '--days-ahead', action='store', dest='days_ahead', help='Number of days forward in time to search. Defaults to 30.', default=30, type=int, ) option_parser.add_option( '-v', '--verbose', action='count', dest='verbose_level', default=1, help='Increase verbose level', ) option_parser.add_option( '-q', '--quiet', action='store_const', const=0, dest='verbose_level', help='Turn off verbose output', ) option_parser.add_option( '--output-file', '-o', action='store', dest='output_file_name', help='Write the output to the named file instead of stdout', default=None, ) option_parser.add_option( '--all', action='store_false', dest='active_only', default=True, help='Include all calendars, not just active.', ) option_parser.add_option( '--input-directory', action='store', dest='input_directory', default=os.path.expanduser('~/Library/Calendars'), help='Directory containing calendars. Defaults to ~/Library/Calendars.', ) option_parser.add_option( '--format', '-f', action='store', dest='format', type='choice', choices=FORMATTER_FACTORIES.keys(), default='org', help='Output format. One of %s. Defaults to "diary".' % FORMATTER_FACTORIES.keys(), ) option_parser.add_option( '--opt', '--formatter-option', action='callback', type='string', callback=remember_formatter_option, help='Formatter-specific option name=value', ) option_parser.add_option( '--help', action='callback', callback=show_verbose_help, help='Verbose help', ) options, calendar_titles = option_parser.parse_args(args) log_level = VERBOSE_LEVELS.get(options.verbose_level, logging.DEBUG) logging.basicConfig(level=log_level, format='%(message)s') config = ConfigParser() config.read([options.config_filename]) # Compute the date range for items to be included in our output. start_date = tz.normalize_to_utc( datetime.datetime.combine( datetime.date.today() - datetime.timedelta(options.days_ago), datetime.time.min, )) end_date = tz.normalize_to_utc( datetime.datetime.combine( datetime.date.today() + datetime.timedelta(options.days_ahead + 1), datetime.time.min, )) logging.info('Starting %d days ago at %s', options.days_ago, start_date.astimezone(tz.local)) logging.info('Ending %d days from now at %s', options.days_ahead, end_date.astimezone(tz.local)) if options.output_file_name: logging.info('Writing to %s', options.output_file_name) # Load the calendars if calendar_titles: calendar_generator = calendars.get_by_titles( path=options.input_directory, titles=calendar_titles) else: calendar_generator = calendars.discover( path=options.input_directory, active_only=options.active_only) # Process the calendar data output = codecs.getwriter('utf-8')(sys.stdout) if options.output_file_name: output = codecs.open(options.output_file_name, 'wt', 'UTF-8') try: formatter = FORMATTER_FACTORIES[options.format](output, config, options) for calendar in calendar_generator: logging.info('Processing: %s', calendar.title) formatter.start_calendar(calendar) for event in filter.unique( filter.by_date_range( calendar.get_events(), start_date, end_date, )): logging.info(' %s', event.summary.value) formatter.add_event(event) formatter.end_calendar(calendar) finally: formatter.close() if output != sys.stdout: output.close() return