How to use the icalendar.Calendar.from_ical 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 CarlFK / veyepar / dj / scripts / addeps.py View on Github external
if ext=='.csv':
            # schedule = list(csv.reader(f))
            schedule = list(csv.DictReader(f))
            if 'desktopsummit.org' in url:
                return self.desktopsummit(schedule,show)

        elif ext=='.xml':

          if url.startswith('file'):
            schedule=xml.etree.ElementTree.XML(f.read())
          else:
            schedule=xml.etree.ElementTree.XML(
                    response.content)

        elif ext=='.ics':
            schedule=Calendar.from_ical(response.content)
            # schedule=Calendar.from_ical(f.read())

        else:
            # lets hope it is json, like everything should be.
            j = response.text
            print( j[:30].__repr__() )

            if url.startswith('file'):
                schedule = json.loads(f.read())
            else:
                schedule = response.json()

            # if it is a python prety printed list:
            # (pyohio 2012)
            # schedule = eval(j)
github ncqgm / gnumed / gnumed / gnumed / client / timelinelib / dataimport / ics.py View on Github external
def _read_calendar_object(self, file_contents):
        try:
            return Calendar.from_ical(file_contents)
        except Exception as pe:
            msg1 = _("Unable to read calendar data.")
            msg2 = "\n\n" + ex_msg(pe)
            raise TimelineIOError(msg1 + msg2)
github gregolsky / TraktCalendarExporter / traktCalendarExporter.py View on Github external
def openOrCreateCalendar():
    if os.path.exists(cfg.ExportFilePath):
        with open(cfg.ExportFilePath, 'rb') as opened:
            return Calendar.from_ical(opened.read())

    cal = Calendar()
    cal.add('prodid', 'Series calendar')
    cal.add('version', '2.0')
    return cal
github pimutils / todoman / todoman / model.py View on Github external
def _read(self, path):
        with open(path, 'rb') as f:
            cal = f.read()
            cal = icalendar.Calendar.from_ical(cal)
            for component in cal.walk('VTODO'):
                return component
github albertyw / csv-ical / csv_ical / convert.py View on Github external
def read_ical(self, ical_file_location):  # type: (str) -> Calendar
        """ Read the ical file """
        with open(ical_file_location, 'r', encoding='utf-8') as ical_file:
            data = ical_file.read()
        self.cal = Calendar.from_ical(data)
        return self.cal
github openstack / karbor / karbor / services / operationengine / engine / triggers / timetrigger / timeformats / calendar_time.py View on Github external
def __init__(self, start_time, pattern):
        super(ICal, self).__init__(start_time, pattern)
        cal = Calendar.from_ical(self._decode_calendar_pattern(pattern))
        vevent = cal.walk('VEVENT')[0]
        self.dtstart = start_time
        self.min_freq = self._get_min_freq(vevent)
        self.rrule_obj = self._get_rrule_obj(vevent, start_time)
github pjimenezmateo / kindle-wallpaper / In the server / programs / parse_ical.py View on Github external
from icalendar import Calendar
import datetime
from datetime import timedelta
import urllib.request
import time
import codecs

#Your private ical URL, if you don't know what to do here, read the README
ICAL_URL = ""

urllib.request.urlretrieve(ICAL_URL, "basic.ics")

cal = Calendar.from_ical(open('basic.ics','rb').read())

all_day_events = []
normal_events = []

for component in cal.walk('vevent'):

    #Offset from GMT timezone depending on Calendar provider (hours = x)
    delta = timedelta(hours = 3)

    date_start = component['DTSTART'].dt + delta

    #Check if it is today
    if( date_start.timetuple().tm_yday == datetime.datetime. now().timetuple().tm_yday ):
        if date_start.timetuple().tm_year == datetime.datetime.now().timetuple().tm_year:

            #Check if is not  all day (It does have time so datetime works)
github novoid / Memacs / memacs / ical.py View on Github external
def _main(self):
        # getting data
        if self._args.calendar_file:
            data = CommonReader.get_data_from_file(self._args.calendar_file,
            encoding=None)
        elif self._args.calendar_url:
            data = CommonReader.get_data_from_url(self._args.calendar_url)

        # read and go through calendar
        cal = Calendar.from_ical(data)
        for component in cal.walk():
            if component.name == "VCALENDAR":
                self.__handle_vcalendar(component)
            elif component.name == "VEVENT":
                self.__handle_vevent(component)
            else:
                logging.debug("Not handling component: " + component.name)
github fsi-tue / fachschaftsempfaenger / fachschaftsempfaenger / calendar.py View on Github external
def events(url):
    """
    Yields a generator of the events in the ical file provided by the url

    - **parameters**, **types**, **return** and **return types**::
        :param url: url to a ical file
        :type url: str
        :return: generator of qua­d­ru­pel in the
                 format (date, time, title, location)
        :rtype: generator
    """
    try:
        response = requests.get(url, verify=False)
        response.encoding = 'utf-8'
        calendar = Calendar.from_ical(response.text).walk('vevent')

        def _key(event):
            return event.decoded('dtstart').strftime("%Y.%m.%d %H:%M")

        calendar = sorted(calendar, key=_key, reverse=False)

    except requests.exceptions.RequestException as e:
        calendar = []
        print("Connection to caldav server failed with error: ", e)

    def _get_date(event):
        return event.decoded('dtstart').strftime("%d.%m.%Y")

    def _get_time(event):
        return event.decoded('dtstart').strftime("%H:%M")
github ncqgm / gnumed / gnumed / gnumed / client / timelinelib / db / backends / ics.py View on Github external
def import_timeline(self, path):
        try:
            ics_file = open(path, "rb")
            try:
                file_contents = ics_file.read()
                try:
                    cal = Calendar.from_ical(file_contents)
                    for event in cal.walk("VEVENT"):
                        event["timeline_id"] = self.event_id_counter.get_next()
                    self.cals.append(cal)
                except Exception, pe:
                    msg1 = _("Unable to read timeline data from '%s'.")
                    msg2 = "\n\n" + ex_msg(pe)
                    raise TimelineIOError((msg1 % abspath(path)) + msg2)
            finally:
                ics_file.close()
        except IOError, e:
            msg = _("Unable to read from file '%s'.")
            whole_msg = (msg + "\n\n%s") % (abspath(self.path), e)
            raise TimelineIOError(whole_msg)