Example #1
0
def week_calendar(username, period):
    config = data.CalendarConfig(
        lang='en',
        title=f"{username}'s Tasks",
        dates=period,
        show_year=True,
        mode='working_hours',
        legend=False,
    )
    events = []
    user_tasks = file.user_row('tasks.csv', user_name=username)
    for task in user_tasks:
        daytime = task['due_time'].split(" ")
        day = daytime[0]
        start = datetime.strftime(datetime.strptime(daytime[1], '%H:%M:%S'),
                                  '%H:%M')
        end = datetime.strftime(
            datetime.strptime(daytime[1], '%H:%M:%S') + timedelta(hours=1),
            '%H:%M')
        events.append(Event(task['title'], day=day, start=start, end=end))

    data.validate_config(config)
    data.validate_events(events, config)

    calendar = Calendar.build(config)
    calendar.add_events(events)
    calendar.save(f"{username}_tasks.png")
Example #2
0
 def add_event(self, *events: Event, **kwargs) -> None:
     """
     Adds the event(s) to the list to draw them later.
     :param events: the event objects
     :param kwargs: the input arguments for the Event constructor
     """
     if events:
         for event in events:
             self.events.add_event(event)
     if kwargs:
         self.events.add_event(Event(**kwargs))
Example #3
0
    def add_event(self, event: Event) -> None:
        """
        Skip the empty events with a duration of fewer than 0 seconds.
        Splits events, if needed, to the separate days. The event in the result list has to be for 1 day only.
        Cut the event's time out of the visible time range.
        Validate events.
        """
        if event.get_duration_seconds(self.config) < 1:
            logging.warning(
                f"Skipping event, the duration is too small: {event}")
            return
        end_date: date = event.get_end_date(self.config)
        start_date: date = event.get_start_date(self.config)
        if end_date < self.config.get_date_range()[0]:
            logging.warning(
                f"Skipping event, it ends before the visible range: {event}")
            return
        if start_date > self.config.get_date_range()[1]:
            logging.warning(
                f"Skipping event, it starts after the visible range: {event}")
            return

        if start_date == end_date or ((end_date - start_date).days == 1
                                      and event.end_time == time(0, 0)):
            self.__do_add_event(event)
        else:
            logging.debug(f'Splitting the event: {event}')
            iter_from: date = max(start_date, self.config.get_date_range()[0])
            iter_to: date = min(end_date, self.config.get_date_range()[1])
            for single_date in time_utils.date_range(iter_from, iter_to):
                next_date: date = single_date + timedelta(days=1)
                if single_date == start_date:
                    fr: datetime = datetime.combine(single_date,
                                                    event.start_time)
                    to: datetime = datetime.combine(next_date, time(0, 0))
                elif single_date == end_date:
                    fr: datetime = datetime.combine(single_date, time(0, 0))
                    to: datetime = datetime.combine(single_date,
                                                    event.end_time)
                else:
                    fr: datetime = datetime.combine(single_date, time(0, 0))
                    to: datetime = datetime.combine(next_date, time(0, 0))
                self.__do_add_event(
                    Event(name=event.name, style=event.style, start=fr,
                          end=to))
Example #4
0
from calendar_view.core.event import Event, EventStyles

config = CalendarConfig(
    lang='en',
    title='Yoga Class Schedule',
    dates='Mo - Su',
    hours='8 - 22',
    show_date=False,
    legend=True,
)
data.validate_config(config)

events = [
    Event(day_of_week=0,
          start='11:00',
          end='12:30',
          name='Ashtanga, 90 mins, with Gina',
          style=EventStyles.GRAY),
    Event(day_of_week=1,
          start='18:00',
          end='19:15',
          name='HOT Core Yoga, 75 mins, with David',
          style=EventStyles.RED),
    Event(day_of_week=2,
          start='09:00',
          end='10:00',
          name='Meditation - Yoga Nidra, 60 mins, with Heena',
          style=EventStyles.BLUE),
    Event(day_of_week=2,
          start='19:00',
          end='20:15',
Example #5
0
from calendar_view.calendar import Calendar
from calendar_view.core import data
from calendar_view.core.event import Event

config = data.CalendarConfig(
    lang='en',
    title='Sprint 23',
    dates='2019-09-23 - 2019-09-27',
    show_year=True,
    mode='working_hours',
    legend=False,
)
events = [
    Event('Planning', day='2019-09-23', start='11:00', end='13:00'),
    Event('Demo', day='2019-09-27', start='15:00', end='16:00'),
    Event('Retrospective', day='2019-09-27', start='17:00', end='18:00'),
]

data.validate_config(config)
data.validate_events(events, config)

calendar = Calendar.build(config)
calendar.add_events(events)
calendar.save("sprint_23.png")