How to use khal - 10 common examples

To help you get started, we’ve selected a few khal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / khal / khal / parse_datetime.py View on Github external
def rrulefstr(repeat, until, locale):
    if repeat in ["daily", "weekly", "monthly", "yearly"]:
        rrule_settings = {'freq': repeat}
        if until:
            until_dt, is_date = guessdatetimefstr(until.split(' '), locale)
            rrule_settings['until'] = until_dt
        return rrule_settings
    else:
        logger.fatal("Invalid value for the repeat option. \
                Possible values are: daily, weekly, monthly or yearly")
        raise FatalError()
github pimutils / khal / khal / controllers.py View on Github external
categories = list([category.strip() for category in categories.split(',')])
    try:
        event = new_vevent(
            locale=conf['locale'], location=location, categories=categories,
            repeat=repeat, until=until, alarms=alarms, dtstart=dtstart,
            dtend=dtend, summary=summary, description=description, timezone=timezone,
        )
    except ValueError as error:
        raise FatalError(error)
    event = Event.fromVEvents(
        [event], calendar=calendar_name, locale=conf['locale'])

    try:
        collection.new(event)
    except ReadOnlyCalendarError:
        raise FatalError(
            'ERROR: Cannot modify calendar "{}" as it is read-only'.format(calendar_name)
        )

    if conf['default']['print_new'] == 'event':
        if format is None:
            format = conf['view']['event_format']
        echo(event.format(format, dt.datetime.now(), env=env))
    elif conf['default']['print_new'] == 'path':
        path = os.path.join(
            collection._calendars[event.calendar]['path'],
            event.href
        )
        echo(path)
    return event
github pimutils / khal / khal / controllers.py View on Github external
def new_from_args(collection, calendar_name, conf, dtstart=None, dtend=None,
                  summary=None, description=None, allday=None, location=None,
                  categories=None, repeat=None, until=None, alarms=None,
                  timezone=None, format=None, env=None):
    """Create a new event from arguments and add to vdirs"""
    if isinstance(categories, str):
        categories = list([category.strip() for category in categories.split(',')])
    try:
        event = new_vevent(
            locale=conf['locale'], location=location, categories=categories,
            repeat=repeat, until=until, alarms=alarms, dtstart=dtstart,
            dtend=dtend, summary=summary, description=description, timezone=timezone,
        )
    except ValueError as error:
        raise FatalError(error)
    event = Event.fromVEvents(
        [event], calendar=calendar_name, locale=conf['locale'])

    try:
        collection.new(event)
    except ReadOnlyCalendarError:
        raise FatalError(
            'ERROR: Cannot modify calendar "{}" as it is read-only'.format(calendar_name)
        )

    if conf['default']['print_new'] == 'event':
        if format is None:
            format = conf['view']['event_format']
        echo(event.format(format, dt.datetime.now(), env=env))
    elif conf['default']['print_new'] == 'path':
        path = os.path.join(
github pimutils / khal / khal / parse_datetime.py View on Github external
else:
                    end = start + default_timedelta_datetime
            elif end.lower() == 'eod':
                end = dt.datetime.combine(start.date(), dt.time.max)
            elif end.lower() == 'week':
                start -= dt.timedelta(days=(start.weekday() - locale['firstweekday']))
                end = start + dt.timedelta(days=8)
            else:
                try:
                    delta = guesstimedeltafstr(end)
                    if allday and delta.total_seconds() % (3600 * 24):
                        # TODO better error class, no logging in here
                        logger.fatal(
                            "Cannot give delta containing anything but whole days for allday events"
                        )
                        raise FatalError()
                    elif delta.total_seconds() == 0:
                        logger.fatal(
                            "Events that last no time are not allowed"
                        )
                        raise FatalError()

                    end = start + delta
                except (ValueError, DateTimeParseError):
                    split = end.split(" ")
                    end, end_allday = guessdatetimefstr(
                        split, locale, default_day=start.date(), in_future=False)
                    if len(split) != 0:
                        continue
                    if allday:
                        end += dt.timedelta(days=1)
github pimutils / khal / khal / ui / editor.py View on Github external
def _rebuild_edit(self):
        firstline = NColumns([
            (13, self.repeat_box),
            (11, self.recurrence_choice),
            (11, self.interval_edit),
        ])
        lines = [firstline]

        if self.recurrence_choice.active == "weekly":
            lines.append(self.weekday_checks)
        if self.recurrence_choice.active == "monthly":
            lines.append(self.monthly_choice)

        nextline = [(16, self.until_choice)]
        if self.until_choice.active == "Until":
            nextline.append((20, self.until_edit))
        elif self.until_choice.active == "Repetitions":
            nextline.append((4, self.repetitions_edit))
github pimutils / khal / khal / ui / editor.py View on Github external
raw_start_time_widget, align='left', width=self._timewidth + 1, left=1)

            raw_end_time_widget = ValidatedEdit(
                dateformat=self.conf['locale']['timeformat'],
                EditWidget=TimeWidget,
                validate=self._validate_end_time,
                edit_text=self.enddt.strftime(self.conf['locale']['timeformat']),
            )
            self.widgets.endtime = urwid.Padding(
                raw_end_time_widget, align='left', width=self._timewidth + 1, left=1)

        columns = NPile([
            self.checkallday,
            NColumns([(5, urwid.Text('From:')), (self._datewidth, self.widgets.startdate), (
                timewidth, self.widgets.starttime)], dividechars=1),
            NColumns(
                [(5, urwid.Text('To:')), (self._datewidth, self.widgets.enddate),
                 (timewidth, self.widgets.endtime)],
                dividechars=1)
        ], focus_item=1)
        urwid.WidgetWrap.__init__(self, columns)
github pimutils / khal / khal / ui / __init__.py View on Github external
self.pane.calendar.original_widget.set_focus_date(new_start)
            self.pane.eventscolumn.original_widget.set_focus_date(new_start)

        if self.editor:
            self.pane.window.backtrack()

        assert not self.editor
        if external_edit:
            self.pane.window.loop.screen.stop()
            text = click.edit(event.raw)
            self.pane.window.loop.screen.start()
            if text is None:
                return
            # KeyErrors can occurr here when we destroy DTSTART,
            # otherwise, even broken .ics files seem to be no problem
            new_event = Event.fromString(
                text,
                locale=self._conf['locale'],
                href=event.href,
                calendar=event.calendar,
                etag=event.etag,
            )
            self.pane.collection.update(new_event)
            update_colors(
                new_event.start_local,
                new_event.end_local,
                (event.recurring or new_event.recurring)
            )
        else:
            self.editor = True
            editor = EventEditor(self.pane, event, update_colors, always_save=always_save)
github pimutils / khal / khal / ui / __init__.py View on Github external
self.pane.calendar.original_widget.set_focus_date(new_start)
            self.pane.eventscolumn.original_widget.set_focus_date(new_start)

        if self.editor:
            self.pane.window.backtrack()

        assert not self.editor
        if external_edit:
            self.pane.window.loop.screen.stop()
            text = click.edit(event.raw)
            self.pane.window.loop.screen.start()
            if text is None:
                return
            # KeyErrors can occurr here when we destroy DTSTART,
            # otherwise, even broken .ics files seem to be no problem
            new_event = Event.fromString(
                text,
                locale=self._conf['locale'],
                href=event.href,
                calendar=event.calendar,
                etag=event.etag,
            )
            self.pane.collection.update(new_event)
            update_colors(
                new_event.start_local,
                new_event.end_local,
                (event.recurring or new_event.recurring)
            )
        else:
            self.editor = True
            editor = EventEditor(self.pane, event, update_colors, always_save=always_save)
github pimutils / khal / khal / ui / editor.py View on Github external
def update_vevent(self):
        self.event.update_summary(get_wrapped_text(self.summary))
        self.event.update_description(get_wrapped_text(self.description))
        self.event.update_location(get_wrapped_text(self.location))
        self.event.update_categories(get_wrapped_text(self.categories).split(','))

        if self.startendeditor.changed:
            self.event.update_start_end(
                self.startendeditor.startdt, self.startendeditor.enddt)
        if self.recurrenceeditor.changed:
            rrule = self.recurrenceeditor.active
            self.event.update_rrule(rrule)

        if self.alarms.changed:
            self.event.update_alarms(self.alarms.get_alarms())
github pimutils / khal / khal / ui / editor.py View on Github external
def update_vevent(self):
        self.event.update_summary(get_wrapped_text(self.summary))
        self.event.update_description(get_wrapped_text(self.description))
        self.event.update_location(get_wrapped_text(self.location))
        self.event.update_categories(get_wrapped_text(self.categories).split(','))

        if self.startendeditor.changed:
            self.event.update_start_end(
                self.startendeditor.startdt, self.startendeditor.enddt)
        if self.recurrenceeditor.changed:
            rrule = self.recurrenceeditor.active
            self.event.update_rrule(rrule)

        if self.alarms.changed:
            self.event.update_alarms(self.alarms.get_alarms())