How to use the icalendar.prop.vText function in icalendar

To help you get started, we’ve selected a few icalendar 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 jelmer / xandikos / newtravel.py View on Github external
props = {
    'categories': opts.categories.split(','),
    'dtstart': vDate(dtstart.date()),
    'created': vDatetime(datetime.datetime.now()),
    'class': 'PUBLIC',
    }
if status is not None:
    props['status'] = status
if location is not None:
    props['location'] = vText(location)
if opts.url:
    props['url'] = vUri(opts.url)
if description is not None:
    props['summary'] = vText(description)
if dtend is not None:
    props['dtend'] = vDate(dtend.date())
if duration is not None:
    props['duration'] = vDuration(duration)

uid = str(uuid.uuid1())
props['UID'] = uid
ev = Event(**props)

c = Calendar()
c.add_component(ev)

fname = uid + '.ics'

url = urllib.parse.urljoin(opts.url, fname)
github entu / entu / appengine / icalendar / cal.py View on Github external
def get_inline(self, name, decode=1):
        """
        Returns a list of values (split on comma).
        """
        vals = [v.strip('" ').encode(vText.encoding)
                  for v in q_split(self[name])]
        if decode:
            return [self._decode(name, val) for val in vals]
        return vals
github nylas-mail-lives / nylas-mail / internal_packages / quick-schedule / backend / backend.py View on Github external
evt['uid'] = '{timestamp}/{email}'.format(
        timestamp=time.mktime(datetime.now(pytz.UTC).timetuple()),
        email=event.organizer.email
    )
    evt.add('priority', 5)

    organizer = vCalAddress('MAILTO:{}'.format(event.organizer.email))
    organizer.params['cn'] = vText(event.organizer.name)
    organizer.params['role'] = vText('CHAIR')
    evt['organizer'] = organizer

    for attendee in event.attendees:
        atnd = vCalAddress('MAILTO:{}'.format(attendee.email))
        atnd.params['cn'] = vText(attendee.name)
        atnd.params['ROLE'] = vText('REQ-PARTICIPANT')
        evt.add('attendee', atnd, encode=0)

    cal.add_component(evt)

    return cal.to_ical()
github collective / icalendar / src / icalendar / tools.py View on Github external
def uid(self, host_name='example.com', unique=''):
        """Generates a unique id consisting of:
            datetime-uniquevalue@host.
        Like:
            20050105T225746Z-HKtJMqUgdO0jDUwm@example.com
        """
        host_name = to_unicode(host_name)
        unique = unique or self.rnd_string()
        today = to_unicode(vDatetime(datetime.today()).to_ical())
        return vText('%s-%s@%s' % (today,
                                   unique,
                                   host_name))
github nylas-mail-lives / nylas-mail / internal_packages / quick-schedule / backend / backend.py View on Github external
evt.add('summary', event.title)
    evt.add('location', event.location)
    evt.add('description', event.description)
    evt.add('dtstart', etime.start.replace(tzinfo=pytz.UTC))
    evt.add('dtend', etime.end.replace(tzinfo=pytz.UTC))
    evt.add('dtstamp', datetime.now(pytz.UTC))

    evt['uid'] = '{timestamp}/{email}'.format(
        timestamp=time.mktime(datetime.now(pytz.UTC).timetuple()),
        email=event.organizer.email
    )
    evt.add('priority', 5)

    organizer = vCalAddress('MAILTO:{}'.format(event.organizer.email))
    organizer.params['cn'] = vText(event.organizer.name)
    organizer.params['role'] = vText('CHAIR')
    evt['organizer'] = organizer

    for attendee in event.attendees:
        atnd = vCalAddress('MAILTO:{}'.format(attendee.email))
        atnd.params['cn'] = vText(attendee.name)
        atnd.params['ROLE'] = vText('REQ-PARTICIPANT')
        evt.add('attendee', atnd, encode=0)

    cal.add_component(evt)

    return cal.to_ical()
github jelmer / xandikos / split.py View on Github external
except KeyError:
        if_match = None
        fname = "%s-%s.ics" % (opts.prefix, uid.replace("/", ""))
        old = None
        url = urllib.parse.urljoin(opts.url, fname)
    else:
        if_match = [etag]
        url = urllib.parse.urljoin(opts.url, href)
    out = Calendar()
    if import_url is not None:
        out['X-IMPORTED-FROM-URL'] = vUri(import_url)
    out.update(list(orig.items()))
    for c in other:
        out.add_component(c)
    if opts.category:
        if isinstance(ev.get('categories', ''), vText):
            ev['categories'] = [ev['categories']]
        ev.setdefault('categories', []).append(vText(opts.category))
    if opts.status and not 'status' in ev:
        ev['status'] = opts.status.upper()
    out.add_component(ev)
    write = hasChanged(old, out)
    if write:
        if old is None:
           added += 1
        else:
           changed += 1
        utils.put(url, out.to_ical(), if_match=if_match)

logger.info('Processed %s. Seen %d, updated %d, new %d', opts.prefix,
             seen, changed, added)
github nylas-mail-lives / nylas-mail / internal_packages / quick-schedule / backend / backend.py View on Github external
evt = Event()
    evt.add('summary', event.title)
    evt.add('location', event.location)
    evt.add('description', event.description)
    evt.add('dtstart', etime.start.replace(tzinfo=pytz.UTC))
    evt.add('dtend', etime.end.replace(tzinfo=pytz.UTC))
    evt.add('dtstamp', datetime.now(pytz.UTC))

    evt['uid'] = '{timestamp}/{email}'.format(
        timestamp=time.mktime(datetime.now(pytz.UTC).timetuple()),
        email=event.organizer.email
    )
    evt.add('priority', 5)

    organizer = vCalAddress('MAILTO:{}'.format(event.organizer.email))
    organizer.params['cn'] = vText(event.organizer.name)
    organizer.params['role'] = vText('CHAIR')
    evt['organizer'] = organizer

    for attendee in event.attendees:
        atnd = vCalAddress('MAILTO:{}'.format(attendee.email))
        atnd.params['cn'] = vText(attendee.name)
        atnd.params['ROLE'] = vText('REQ-PARTICIPANT')
        evt.add('attendee', atnd, encode=0)

    cal.add_component(evt)

    return cal.to_ical()
github mollyproject / mollyproject / molly / apps / feeds / providers / ical.py View on Github external
try:
                        item.dt_start = vDatetime.from_ical(str(
                            component.get('DTSTART')))
                    except ValueError, ve:
                        item.dt_start = vDate.from_ical(str(
                            component.get('DTSTART')))

                    if component.get('DTEND'):
                        try:
                            item.dt_end = vDatetime.from_ical(str(
                                component.get('DTEND')))
                        except ValueError, ve:
                            item.dt_end = vDate.from_ical(str(
                                component.get('DTEND')))

                    item.title = vText.from_ical(str(
                        component.get('SUMMARY')).strip())

                    if component.get('URL'):
                        item.link = str(component.get('URL'))

                    if component.get('DESCRIPTION'):
                        item.description = sanitise_html(vText.from_ical(str(
                            component.get('DESCRIPTION'))))

                    if str(component.get('LOCATION')) != '':
                        location, created = vCard.objects.get_or_create(
                                name=vText.from_ical(str(
                                    component.get('LOCATION')).strip()))
                        # in the future, we could imagine to (try to) geocode
                        # the location to get a point field...
                        location.save()
github plone / plone.app.event / plone / app / event / ical / exporter.py View on Github external
def attendee(self):
        # TODO: revisit and implement attendee export according to RFC
        ret = []
        for attendee in self.event.attendees or []:
            att = icalendar.prop.vCalAddress(attendee)
            att.params['cn'] = icalendar.prop.vText(attendee)
            att.params['ROLE'] = icalendar.prop.vText('REQ-PARTICIPANT')
            ret.append(att)
        return {'value': ret}
github jelmer / xandikos / split.py View on Github external
fname = "%s-%s.ics" % (opts.prefix, uid.replace("/", ""))
        old = None
        url = urllib.parse.urljoin(opts.url, fname)
    else:
        if_match = [etag]
        url = urllib.parse.urljoin(opts.url, href)
    out = Calendar()
    if import_url is not None:
        out['X-IMPORTED-FROM-URL'] = vUri(import_url)
    out.update(list(orig.items()))
    for c in other:
        out.add_component(c)
    if opts.category:
        if isinstance(ev.get('categories', ''), vText):
            ev['categories'] = [ev['categories']]
        ev.setdefault('categories', []).append(vText(opts.category))
    if opts.status and not 'status' in ev:
        ev['status'] = opts.status.upper()
    out.add_component(ev)
    write = hasChanged(old, out)
    if write:
        if old is None:
           added += 1
        else:
           changed += 1
        utils.put(url, out.to_ical(), if_match=if_match)

logger.info('Processed %s. Seen %d, updated %d, new %d', opts.prefix,
             seen, changed, added)