def vertical_month(month=datetime.date.today().month, year=datetime.date.today().year, today=datetime.date.today(), weeknumber=False, count=3, firstweekday=0): """ returns a list() of str() of weeks for a vertical arranged calendar :param month: first month of the calendar, if non given, current month is assumed :type month: int :param year: year of the first month included, if non given, current year is assumed :type year: int :param today: day highlighted, if non is given, current date is assumed :type today: datetime.date() :returns: calendar strings, may also include some ANSI (color) escape strings :rtype: list() of str() >>> vertical_month(month=12, year=2011, today=datetime.date(2011,12,12)) ['\\x1b[1m Mo Tu We Th Fr Sa Su\\x1b[0m ', '\\x1b[1mDec \\x1b[0m28 29 30 1 2 3 4 ', ' 5 6 7 8 9 10 11 ', ' \\x1b[7m12\\x1b[0m 13 14 15 16 17 18 ', ' 19 20 21 22 23 24 25 ', '\\x1b[1mJan \\x1b[0m26 27 28 29 30 31 1 ', ' 2 3 4 5 6 7 8 ', ' 9 10 11 12 13 14 15 ', ' 16 17 18 19 20 21 22 ', ' 23 24 25 26 27 28 29 ', '\\x1b[1mFeb \\x1b[0m30 31 1 2 3 4 5 ', ' 6 7 8 9 10 11 12 ', ' 13 14 15 16 17 18 19 ', ' 20 21 22 23 24 25 26 ', '\\x1b[1mMar \\x1b[0m27 28 29 1 2 3 4 '] """ khal = list() w_number = ' ' if weeknumber else '' calendar.setfirstweekday(firstweekday) khal.append(bstring(' ' + calendar.weekheader(2) + ' ' + w_number)) for _ in range(count): for week in calendar.Calendar(firstweekday).monthdatescalendar( year, month): new_month = len([day for day in week if day.day == 1]) strweek = str_week(week, today) if new_month: m_name = bstring(calendar.month_abbr[week[6].month].ljust(4)) else: m_name = ' ' w_number = bstring( ' ' + str(getweeknumber(week[0]))) if weeknumber else '' sweek = m_name + strweek + w_number if sweek != khal[-1]: khal.append(sweek) month = month + 1 if month > 12: month = 1 year = year + 1 return khal
def __init__(self, collection, firstweekday=0, encoding='utf-8'): today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) daylist = [(today, 'Today:'), (tomorrow, 'Tomorrow:')] event_column = list() for day, dayname in daylist: # TODO unify allday and datetime events start = datetime.datetime.combine(day, datetime.time.min) end = datetime.datetime.combine(day, datetime.time.max) event_column.append(bstring(dayname)) all_day_events = collection.get_allday_by_time_range(day) events = collection.get_datetime_by_time_range(start, end) for event in all_day_events: event_column.append(aux.colored(event.compact(day), event.color)) events.sort(key=lambda e: e.start) for event in events: event_column.append(aux.colored(event.compact(day), event.color)) calendar_column = calendar_display.vertical_month( firstweekday=firstweekday) # if the event column is longer than the calendar_column: increase # length of the former missing = len(event_column) - len(calendar_column) if missing > 0: calendar_column = calendar_column + missing * [25 * ' '] rows = [' '.join(one) for one in izip_longest(calendar_column, event_column, fillvalue='')] print('\n'.join(rows).encode(encoding))
def vertical_month(month=datetime.date.today().month, year=datetime.date.today().year, today=datetime.date.today(), weeknumber=False, count=3, firstweekday=0): """ returns a list() of str() of weeks for a vertical arranged calendar :param month: first month of the calendar, if non given, current month is assumed :type month: int :param year: year of the first month included, if non given, current year is assumed :type year: int :param today: day highlighted, if non is given, current date is assumed :type today: datetime.date() :returns: calendar strings, may also include some ANSI (color) escape strings :rtype: list() of str() >>> vertical_month(month=12, year=2011, today=datetime.date(2011,12,12)) ['\\x1b[1m Mo Tu We Th Fr Sa Su\\x1b[0m ', '\\x1b[1mDec \\x1b[0m28 29 30 1 2 3 4 ', ' 5 6 7 8 9 10 11 ', ' \\x1b[7m12\\x1b[0m 13 14 15 16 17 18 ', ' 19 20 21 22 23 24 25 ', '\\x1b[1mJan \\x1b[0m26 27 28 29 30 31 1 ', ' 2 3 4 5 6 7 8 ', ' 9 10 11 12 13 14 15 ', ' 16 17 18 19 20 21 22 ', ' 23 24 25 26 27 28 29 ', '\\x1b[1mFeb \\x1b[0m30 31 1 2 3 4 5 ', ' 6 7 8 9 10 11 12 ', ' 13 14 15 16 17 18 19 ', ' 20 21 22 23 24 25 26 ', '\\x1b[1mMar \\x1b[0m27 28 29 1 2 3 4 '] """ khal = list() w_number = ' ' if weeknumber else '' calendar.setfirstweekday(firstweekday) khal.append(bstring(' ' + calendar.weekheader(2) + ' ' + w_number)) for _ in range(count): for week in calendar.Calendar(firstweekday).monthdatescalendar(year, month): new_month = len([day for day in week if day.day == 1]) strweek = str_week(week, today) if new_month: m_name = bstring(calendar.month_abbr[week[6].month].ljust(4)) else: m_name = ' ' w_number = bstring(' ' + str(getweeknumber(week[0]))) if weeknumber else '' sweek = m_name + strweek + w_number if sweek != khal[-1]: khal.append(sweek) month = month + 1 if month > 12: month = 1 year = year + 1 return khal
def __init__(self, conf): super(Display, self).__init__(conf) today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) daylist = [(today, 'Today:'), (tomorrow, 'Tomorrow:')] event_column = list() for day, dayname in daylist: # TODO unify allday and datetime events start = datetime.datetime.combine(day, datetime.time.min) end = datetime.datetime.combine(day, datetime.time.max) event_column.append(bstring(dayname)) all_day_events = list() events = list() for account in conf.sync.accounts: readonly = conf.accounts[account]['readonly'] color = conf.accounts[account]['color'] all_day_events += self.dbtool.get_allday_range( day, account_name=account, color=color, readonly=readonly, unicode_symbols=conf.default.unicode_symbols, show_deleted=False) events += self.dbtool.get_time_range( start, end, account, color=color, readonly=readonly, unicode_symbols=conf.default.unicode_symbols, show_deleted=False) for event in all_day_events: event_column.append(aux.colored(event.compact(day), event.color)) events.sort(key=lambda e: e.start) for event in events: event_column.append(aux.colored(event.compact(day), event.color)) calendar_column = calendar_display.vertical_month() missing = len(event_column) - len(calendar_column) if missing > 0: calendar_column = calendar_column + missing * [25 * ' '] rows = [' '.join(one) for one in izip_longest(calendar_column, event_column, fillvalue='')] print('\n'.join(rows).encode(conf.default.encoding))
def print_month(month=datetime.date.today().month, year=datetime.date.today().year, today=datetime.date.today()): """returns a single month calendar, current date highlighted, much like cal(1) or python calendar.prmonth """ khal = '' mycal = calendar.Calendar(0) # 0: week starts on monday month_name = calendar.month_name[month] + ' ' + str(year) khal = month_name.center(20) + '\n' khal = khal + bstring('Mo Tu We Th Fr Sa Su') + '\n' for mday, wday in mycal.itermonthdays2(year, month): if mday == 0: mday = '' elif mday == today.day and month == today.month and year == today.year: mday = rstring(str(mday).rjust(2)) khal = khal + str(mday).rjust(2) + ' ' if wday % 7 == 6: khal = khal + '\n' khal = khal + '\n' return khal