def get_agenda(collection, locale, dates=None, firstweekday=0, days=None, events=None, width=45, full=False, show_all_days=False): """returns a list of events scheduled for all days in daylist included are header "rows" :param collection: :type collection: khalendar.CalendarCollection :param dates: a list of all dates for which the events should be return, including what should be printed as a header :type collection: list(str) :param show_all_days: True if all days must be shown, event without event :type show_all_days: Boolean :returns: a list to be printed as the agenda for the given days :rtype: list(str) """ event_column = list() if days is None: days = 2 if dates is None or len(dates) == 0: dates = [datetime.date.today()] else: try: dates = [ aux.guessdatetimefstr([date], locale)[0].date() if not isinstance(date, datetime.date) else date for date in dates ] except InvalidDate as error: logging.fatal(error) sys.exit(1) if days is not None: daylist = [date + datetime.timedelta(days=one) for one in range(days) for date in dates] daylist.sort() daylist = construct_daynames(daylist, locale['longdateformat']) for day, dayname in daylist: events = sorted(collection.get_events_on(day)) if not events and not show_all_days: continue event_column.append(style(dayname, bold=True)) for event in events: lines = list() items = event.relative_to(day, full).splitlines() for item in items: lines += textwrap.wrap(item, width) event_column.extend([colored(line, event.color) for line in lines]) if event_column == []: event_column = [style('No events', bold=True)] return event_column
def at(ctx, datetime=None): '''Show all events scheduled for DATETIME. if DATETIME is given (or the string `now`) all events scheduled for this moment are shown, if only a time is given, the date is assumed to be today ''' collection = build_collection(ctx) locale = ctx.obj['conf']['locale'] dtime_list = list(datetime) if dtime_list == [] or dtime_list == ['now']: import datetime dtime = datetime.datetime.now() else: try: dtime, _ = aux.guessdatetimefstr(dtime_list, locale) except ValueError: logger.fatal( '{} is not a valid datetime (matches neither {} nor {} nor' ' {})'.format( ' '.join(dtime_list), locale['timeformat'], locale['datetimeformat'], locale['longdatetimeformat'])) sys.exit(1) dtime = locale['local_timezone'].localize(dtime) dtime = dtime.astimezone(pytz.UTC) events = collection.get_events_at(dtime) event_column = list() term_width, _ = get_terminal_size() for event in events: lines = list() items = event.event_description.splitlines() for item in items: lines += textwrap.wrap(item, term_width) event_column.extend( [colored(line, event.color, bold_for_light_color=ctx.obj['conf']['view']['bold_for_light_color']) for line in lines] ) click.echo( '\n'.join(event_column).encode(ctx.obj['conf']['locale']['encoding']) )
def at(ctx, datetime=None): '''Show all events scheduled for DATETIME. if DATETIME is given (or the string `now`) all events scheduled for this moment are shown, if only a time is given, the date is assumed to be today ''' collection = build_collection(ctx) locale = ctx.obj['conf']['locale'] dtime_list = list(datetime) if dtime_list == [] or dtime_list == ['now']: import datetime dtime = datetime.datetime.now() else: try: dtime, _ = aux.guessdatetimefstr(dtime_list, locale) except ValueError: logger.fatal( '{} is not a valid datetime (matches neither {} nor {} nor' ' {})'.format(' '.join(dtime_list), locale['timeformat'], locale['datetimeformat'], locale['longdatetimeformat'])) sys.exit(1) dtime = locale['local_timezone'].localize(dtime) dtime = dtime.astimezone(pytz.UTC) events = collection.get_events_at(dtime) event_column = list() term_width, _ = get_terminal_size() for event in events: lines = list() items = event.event_description.splitlines() for item in items: lines += textwrap.wrap(item, term_width) event_column.extend([ colored(line, event.color, bold_for_light_color=ctx.obj['conf']['view'] ['bold_for_light_color']) for line in lines ]) click.echo('\n'.join(event_column).encode( ctx.obj['conf']['locale']['encoding']))
def test_time_tomorrow(self): assert (self.tomorrow16, False) == \ guessdatetimefstr('16:00'.split(), locale=locale_de, default_day=tomorrow)
def test_tomorrow(self): assert (self.tomorrow16, False) == \ guessdatetimefstr('tomorrow 16:00 16:00'.split(), locale=locale_de)
def test_today(self): today13 = datetime.combine(date.today(), time(13, 0)) assert (today13, False) == guessdatetimefstr(['today', '13:00'], locale_de) assert today == guessdatetimefstr(['today'], locale_de)[0].date()
def get_agenda(collection, locale, dates=None, firstweekday=0, days=None, events=None, width=45, show_all_days=False): """returns a list of events scheduled for all days in daylist included are header "rows" :param collection: :type collection: khalendar.CalendarCollection :param dates: a list of all dates for which the events should be return, including what should be printed as a header :type collection: list(str) :param show_all_days: True if all days must be shown, event without event :type show_all_days: Boolean :returns: a list to be printed as the agenda for the given days :rtype: list(str) """ event_column = list() if days is None: days = 2 if dates is None or len(dates) == 0: dates = [datetime.date.today()] else: try: dates = [ aux.guessdatetimefstr([date], locale)[0].date() if not isinstance(date, datetime.date) else date for date in dates ] except InvalidDate as error: logging.fatal(error) sys.exit(1) if days is not None: daylist = [date + datetime.timedelta(days=one) for one in range(days) for date in dates] daylist.sort() daylist = construct_daynames(daylist, locale['longdateformat']) localize = locale['local_timezone'].localize for day, dayname in daylist: start = localize(datetime.datetime.combine(day, datetime.time.min)) end = localize(datetime.datetime.combine(day, datetime.time.max)) # TODO unify allday and datetime events all_day_events = collection.get_allday_by_time_range(day) events = collection.get_datetime_by_time_range(start, end) if len(events) == 0 and len(all_day_events) == 0 and not show_all_days: continue event_column.append(style(dayname, bold=True)) events.sort(key=lambda e: e.start) for event in itertools.chain(all_day_events, events): desc = textwrap.wrap(event.relative_to(day), width) event_column.extend([colored(d, event.color) for d in desc]) if event_column == []: event_column = [style('No events', bold=True)] return event_column
def get_agenda(collection, locale, dates=None, firstweekday=0, days=None, events=None, width=45, full=False, show_all_days=False, bold_for_light_color=True): """returns a list of events scheduled for all days in daylist included are header "rows" :param collection: :type collection: khalendar.CalendarCollection :param dates: a list of all dates for which the events should be return, including what should be printed as a header :type collection: list(str) :param show_all_days: True if all days must be shown, event without event :type show_all_days: Boolean :returns: a list to be printed as the agenda for the given days :rtype: list(str) """ event_column = list() if days is None: days = 2 if dates is None or len(dates) == 0: dates = [datetime.date.today()] else: try: dates = [ aux.guessdatetimefstr([date], locale)[0].date() if not isinstance(date, datetime.date) else date for date in dates ] except InvalidDate as error: logging.fatal(error) sys.exit(1) if days is not None: daylist = [ date + datetime.timedelta(days=one) for one in range(days) for date in dates ] daylist.sort() daylist = construct_daynames(daylist, locale['longdateformat']) for day, dayname in daylist: events = sorted(collection.get_events_on(day)) if not events and not show_all_days: continue if event_column: event_column.append('') event_column.append(style(dayname, bold=True)) for event in events: lines = list() items = event.relative_to(day, full).splitlines() for item in items: lines += textwrap.wrap(item, width) event_column.extend([ colored(line, event.color, bold_for_light_color=bold_for_light_color) for line in lines ]) if event_column == []: event_column = [style('No events', bold=True)] return event_column