How to use the icalendar.Event 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 Aalto-LeTech / a-plus / course / views.py View on Github external
def get(self, request, *args, **kwargs):
        cal = icalendar.Calendar()
        cal.add('prodid', '-// {} calendar //'.format(settings.BRAND_NAME))
        cal.add('version', '2.0')
        for module in self.instance.course_modules.all():
            event = icalendar.Event()
            event.add('summary', module.name)
            event.add('dtstart',
                module.closing_time - datetime.timedelta(hours=1))
            event.add('dtend', module.closing_time)
            event.add('dtstamp', module.closing_time)
            event['uid'] = "module/" + str(module.id) + "/A+"
            cal.add_component(event)

        return HttpResponse(cal.to_ical(),
            content_type="text/calendar; charset=utf-8")
github coderedcorp / coderedcms / coderedcms / models / page_models.py View on Github external
def convert_to_ical_format(self, dt_start=None, dt_end=None, occurrence=None):
        ical_event = ICalEvent()
        ical_event.add('summary', self.title)
        if self.address:
            ical_event.add('location', self.address)

        if dt_start:
            ical_event.add('dtstart', dt_start)

            if dt_end:
                ical_event.add('dtend', dt_end)

        if occurrence:
            freq = occurrence.repeat.split(":")[1] if occurrence.repeat else None
            repeat_until = occurrence.repeat_until.strftime(
                "%Y%m%dT000000Z") if occurrence.repeat_until else None

            ical_event.add('dtstart', occurrence.start)
github ninjatrench / DeveloperHorizon / controller / rss.py View on Github external
def build_event_rss(self, entry):
        e = Event()
        e['UID'] = entry.id
        e['SUMMARY'] = entry.title
        e['DESCRIPTION'] = entry.description
        e['URL'] = entry.link
        if entry.date:
            e['DTSTAMP'] = entry.date
        self.events.append(e)
github entu / entu / appengine / controllers / ical.py View on Github external
event = Event()
                    event.add('summary', leecher.displayname)
                    # event.add('description', subbubble.displayinfo)
                    if subbubble.start_datetime.strftime('%H:%M') == '00:00':
                        event.add('dtstart', subbubble.start_datetime.date())
                    else:
                        event.add('dtstart', subbubble.start_datetime)
                    if subbubble.end_datetime.strftime('%H:%M') == '00:00':
                        event.add('dtend', subbubble.end_datetime.date())
                    else:
                        event.add('dtend', subbubble.end_datetime)
                    event.add('dtstamp', subbubble.x_changed)
                    event['uid'] = '%s@artun.ee' % subbubble.key()

                if emptytime:
                    event = Event()
                    event.add('summary', '')
                    # event.add('description', subbubble.displayinfo)
                    if subbubble.start_datetime.strftime('%H:%M') == '00:00':
                        event.add('dtstart', subbubble.start_datetime.date())
                    else:
                        event.add('dtstart', subbubble.start_datetime)
                    if subbubble.end_datetime.strftime('%H:%M') == '00:00':
                        event.add('dtend', subbubble.end_datetime.date())
                    else:
                        event.add('dtend', subbubble.end_datetime)
                    event.add('dtstamp', subbubble.x_changed)
                    event['uid'] = '%s@artun.ee' % subbubble.key()



                # for leecher in subbubble.GetRelatives('leecher'):
github openstates / billy / billy / web / public / views / events.py View on Github external
def event_ical(request, abbr, event_id):
    event = db.events.find_one({'_id': event_id})
    if event is None:
        raise Http404

    x_name = "X-BILLY"

    cal = Calendar()
    cal.add('prodid', '-//Open States//billy//')
    cal.add('version', billy.__version__)

    cal_event = Event()
    cal_event.add('summary', event['description'])
    cal_event['uid'] = "%s@%s" % (event['_id'], get_domain())
    cal_event.add('priority', 5)
    cal_event.add('dtstart', event['when'])
    cal_event.add('dtend', (event['when'] + datetime.timedelta(hours=1)))
    cal_event.add('dtstamp', event['updated_at'])

    if "participants" in event:
        for participant in event['participants']:
            name = participant['participant']
            cal_event.add('attendee', name)
            if "id" in participant and participant['id']:
                cal_event.add("%s-ATTENDEE-ID" % (x_name), participant['id'])

    if "related_bills" in event:
        for bill in event['related_bills']:
github mikelambert / dancedeets-monorepo / scrapers / scrapy / classes / spiders / la_evolution.py View on Github external
def parse_classes(self, response):
        past_horizon = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
        ical_body = response.body.decode('utf-8')
        calendar = icalendar.Calendar.from_ical(ical_body)
        for event in calendar.subcomponents:
            try:
                if not isinstance(event, icalendar.Event):
                    continue
                #TODO: What do we want to do with the longform event['description']
                summary = str(event['summary'])
                instructor_re = r' (?:w/|with) (.*?)(?: -|$)'
                match = re.search(instructor_re, summary)
                if match:
                    teacher = match.group(1)
                    name = re.sub(instructor_re, '', summary)
                else:
                    name = summary
                    match = re.search(r'(?:Instructors?|Teachers?): ([^\n]*)', event.get('description', ''))
                    if match:
                        teacher = match.group(1).strip()
                    else:
                        teacher = ''
                if not self._street_style(name):
github csvenja / SFU-iCalendar / grabber.py View on Github external
cal['version'] = '2.0'
		cal['prodid'] = '-//Simon Fraser University//Svenja Cao//EN'
		
		for class_item in classes:
			for lesson in class_item['lessons']:
				
				start_date = datelize(lesson['start_date'])
				start_time = timelize(lesson['start_time'])
				end_time = timelize(lesson['end_time'])
				start = datetime.combine(start_date, start_time)
				end = datetime.combine(start_date, end_time)
				end_date = datelize(lesson['end_date'])
				until = datetime.combine(end_date, end_time)
				
				for day in lesson['days']:
					event = Event()
					if lesson['start_date'] == lesson['end_date']:
						event.add('summary', class_item['name'] + ' Final')
					else:
						event.add('summary', class_item['name'] + ' ' + class_item['component'])
					event.add('dtstart', start)
					event.add('dtend', end)
					event.add('rrule', {'freq': 'weekly', 'byday': day, 'until': until, 'wkst': 'SU'})
					event.add('location', lesson['location'])
					if 'instructor' in lesson:
						event.add('description', 'Instructor: ' + lesson['instructor'] + '\nSection: ' + class_item['section'])
					else:
						event.add('description', 'Section: ' + class_item['section'])
					event['uid'] = str(uuid1()) + '@SFU'
					cal.add_component(event)
					
		return cal.to_ical()
github GeneralizedLearningUtilities / SuperGLU / python_module / SuperGLU / Services / iCalReader / iCalReader.py View on Github external
def addTaskToCalendar(self, task, calendarData, startTime, endTime=None, duration=None):
        if startTime is None:
            logInfo("startTime not found, will not add task to ", 3)
            return
        
        calenderAsObject = Calendar.from_ical(calendarData.calendarData)
        newEvent = Event()
        newEvent.add('summary', task.displayName)
        newEvent.add(COMMENT_KEY, "{0}={1}".format(TASK_ID, task.taskId))
        
        
        startTimeAsDateTime = datetime.strptime(startTime, DATE_TIME_FORMAT)
        newEvent.add(START_TIME_KEY, startTimeAsDateTime)
        
        if endTime is not None:
            endTimeAsDateTime = datetime.strptime(endTime, DATE_TIME_FORMAT)
            newEvent.add('dtend', endTimeAsDateTime)
            
        elif duration is not None:
            newEvent.add('duration', duration)
            
        calenderAsObject.add_component(newEvent)
        calendarData.calendarData = calenderAsObject.to_ical()
github ColoradoSchoolOfMines / mozzarella / mozzarella / controllers / schedule.py View on Github external
def ical_schedule(self):
        """ Returns the iCalendar version of the schedule """
        cal = Calendar()
        cal.add('prodid', config.get('meetings.icalendar.prodid'))
        cal.add('version', '2.0')

        for m in self.meetings.all():
            event = Event()
            event.add('summary', m.title)
            event.add('description', m.description)
            event.add('location', m.location)
            d = m.date.replace(tzinfo=pytz.timezone(config.get('meetings.timezone')))
            event.add('dtstart', d)
            event.add('dtend', d + m.duration)
            event.add('dtstamp', d)

            cal.add_component(event)

        return cal.to_ical()
github indico / indico / indico / web / http_api / metadata / ical.py View on Github external
def serialize_event(cal, fossil, now, id_prefix="indico-event"):
    event = ical.Event()
    event.add('uid', '{}-{}@{}'.format(id_prefix, fossil['id'], url_parse(config.BASE_URL).host))
    event.add('dtstamp', now)
    event.add('dtstart', _deserialize_date(fossil['startDate']))
    event.add('dtend', _deserialize_date(fossil['endDate']))
    event.add('url', fossil['url'])
    event.add('summary', to_unicode(fossil['title']))
    loc = fossil['location'] or ''
    if loc:
        loc = to_unicode(loc)
    if fossil['roomFullname']:
        loc += ' ' + to_unicode(fossil['roomFullname'])
    event.add('location', loc)
    description = ''
    if fossil.get('speakers'):
        speakers = ('{} ({})'.format(speaker['fullName'].encode('utf-8'),
                                     speaker['affiliation'].encode('utf-8')) for speaker in fossil['speakers'])