Beispiel #1
0
 def __init__(self, ical_string, start_date, end_date, new_events):
     self.ical = Calendar.from_string(ical_string)
     self.simpl_ical = Calendar()
     self.new_events = new_events
     self.new_events.sort(key=lambda x: x.duration, reverse=True)
     self.start_date = start_date - start_date%30 + 30
     self.end_date = end_date - end_date%30 + 30
Beispiel #2
0
 def getCalendar(self, sName):
     Cal = None
     try:
         s = self.readCalendar(sName)
         Cal = Calendar.from_string(s)
     except Exception, param:
         print 'Except error 77'
Beispiel #3
0
def ical2json(body, ctype):
    '''
    Convert iCalendar info to Exhibit JSON
    (see: http://www.ibm.com/developerworks/web/library/wa-realweb6/ )

    Sample request:
    * curl --request POST --data-binary "@foo.ics" --header "Content-Type: text/calendar" "http://localhost:8880/ical.json"
    '''
    ids = set()
    entries = []
    cal = Calendar.from_string(body)
    #[ c['UID'] for c in  cal.subcomponents if c.name == 'VEVENT' ]
    for count, component in enumerate(cal.walk()):
        #if count > MAXRECORDS: break
        if component.name != 'VEVENT': continue
        entry = {}
        entry['summary'] = unicode(component['SUMMARY'])
        entry['label'] = entry['summary'] + '_' + str(count)
        entry['start'] = component['DTSTART'].dt.isoformat()
        entry['end'] = component['DTEND'].dt.isoformat()
        if "URL" in component:
            entry['url'] = component['URL']
        # These are Outlook specific(?)
        if "DESCRIPTION" in component:
            entry['description'] = unicode(component['DESCRIPTION'])
        if "UID" in component:
            entry['id'] = unicode(component['UID'])
        if "DTSTAMP" in component:
            entry['timestamp'] = component['DTSTAMP'].dt.isoformat()

        entries.append(entry)
    return json.dumps({'items': entries}, indent=4)
Beispiel #4
0
def main():
    """
    Perform iCalendar to hCalendar rendering.
    """
    # Establish the calendar URL and output file.
    ics_url = len(sys.argv) > 1 and sys.argv[0] or ICS_URL
    html_dir = len(sys.argv) > 2 and sys.argv[1] or HTML_DIR

    # Get the calendar via URL and parse the data
    cal = Calendar.from_string(HTTPCache(ics_url).content())

    # Create HTML_DIR if it doesn't already exist
    if not os.path.exists(html_dir): os.makedirs(html_dir)

    # Process calendar components.
    for event in cal.walk():

        # Skip this calendar component if it's not an event.
        if not type(event) is Event: continue

        # Summarize the event data, make a hash, build a filename.
        hash_src = ','.join(['%s=%s' % x for x in event.items()])
        hash = md5(hash_src).hexdigest()
        hcal_fn = os.path.join(html_dir, '%s.html' % hash)

        # Build the hCalendar content and write out to file.
        hcal_out = HEVENT_TMPL % ICalTmplWrapper(event)
        open(hcal_fn, 'w').write(hcal_out)
Beispiel #5
0
    def get_ooo_people(self):
        h = httplib2.Http()
        h.add_credentials(self.wiki_user, self.wiki_pass)
        res, icalstring = h.request(self.wiki_ooo_url)
        # Something funky going on in that ical
        icalstring = re.sub("TZOFFSETFROM:-065956", "TZOFFSETFROM:-0600", icalstring)
        cal = Calendar.from_string(icalstring)
        ooo_emails = list()
        now = datetime.date.today()
        print "Looking for vacations on", now
        for s in cal.walk("VEVENT"):
            ooo_startdate = s.decoded("DTSTART")
            if type(ooo_startdate) == datetime.datetime:
                ooo_startdate = ooo_startdate.date()

            ooo_enddate = s.decoded("DTEND")
            if type(ooo_enddate) == datetime.datetime:
                ooo_enddate = ooo_enddate.date()

            if now >= ooo_startdate and now < ooo_enddate:
                print "someone is ooo today:", s
                ooo_org = s.decoded("ORGANIZER", default="UNKNOWN")
                ooo_match = re.match("(mailto:)*(.*)", ooo_org)
                if ooo_org != "UNKNOWN" and ooo_match:
                    ooo_email = ooo_match.group(2)
                    ooo_emails.append(ooo_email)

        return ooo_emails
Beispiel #6
0
 def delete(self, cal, uri, uid):
 
     if not self.__resource:
         if not self.__open(uri, 'w'):
             print "could not open \"%s\", event not deleted" % uri
             return False
     else:
         if not self.refresh(uri):
             print "could not refresh \"%s\", event not deleted" % uri
             return False
     
     for child in self.__resource.get_child_objects():
     
         c = Calendar.from_string( child.get().read() )
         for ev in c.walk('VEVENT'):
         
             print "UID for calendar with event %s is %s" % (ev['summary'], ev.decoded('uid', "-1"))
             if ev.decoded('uid', -1) == uid:
                 # We need to delete by the file's name
                 #self.__resource.delete(str(uid) + ".ics")
                 path = child.url.path
                 if path[-1] == '/':
                     path = path[:-1]
                 self.__resource.delete(path.split('/')[-1])
                 # Trigger a re-read ASAP
                 self.__pollCntr = POLL_CYCLES
                 break
     
     # Maybe it succeeded...
     # At least the resource doesn't need to be re-opened
     return True
Beispiel #7
0
def get_calender_for_month(cn_session, year, month):
    """docstring for get_calender"""
    export_page = cn_session.request("SCHEDULER_EXPORT_START",("000272", "Y%dM%d"%(year,month)))
    m=re.search(r"<a href=\"([0-9a-z/?]+)\">Kalenderdatei</a>",export_page)
    file_url = url+m.group(1)
    r = urllib2.urlopen(file_url)
    cal = Calendar.from_string(r.read())
def main():
    """
    Perform iCalendar to hCalendar rendering.
    """
    # Establish the calendar URL and output file.
    ics_url   = len(sys.argv) > 1 and sys.argv[0] or ICS_URL
    html_dir = len(sys.argv) > 2 and sys.argv[1] or HTML_DIR
        
    # Get the calendar via URL and parse the data
    cal = Calendar.from_string(HTTPCache(ics_url).content())

    # Create HTML_DIR if it doesn't already exist
    if not os.path.exists(html_dir): os.makedirs(html_dir)
    
    # Process calendar components.
    for event in cal.walk():
        
        # Skip this calendar component if it's not an event.
        if not type(event) is Event: continue
        
        # Summarize the event data, make a hash, build a filename.
        hash_src = ','.join(['%s=%s' % x for x in event.items()])
        hash     = md5(hash_src).hexdigest()
        hcal_fn  = os.path.join(html_dir, '%s.html' % hash)

        # Build the hCalendar content and write out to file.
        hcal_out = HEVENT_TMPL % ICalTmplWrapper(event)
        open(hcal_fn, 'w').write(hcal_out)
Beispiel #9
0
 def load_ical(self):
     logging.debug("Loading iCal from url %s" % self.ical_url)
     try:
         req = urlopen(self.ical_url)
         return Calendar.from_string(req.read())
     except URLError:
         logging.error("Unable to retrieve iCal")
Beispiel #10
0
def convert_from_url(url):
    url = 'http://%s' % url
    uh = urlopen(url)
    if uh.getcode() != 200:
        abort(404)
    ics = uh.read()
    uh.close()
    cal = Calendar.from_string(ics)
    data = {}
    data[cal.name] = dict(cal.items())
    
    for component in cal.subcomponents:
        if not data[cal.name].has_key(component.name):
            data[cal.name][component.name] = []
            
        comp_obj = {}
        for item in component.items():
            comp_obj[item[0]] = unicode(item[1])
        
        data[cal.name][component.name].append(comp_obj)
    
    resp = jsonify(data)
    if 'callback' in request.args:
        resp.data = "%s(%s);" % (request.args['callback'], resp.data)
    return resp
Beispiel #11
0
def get_sio():
    ''' get information from SIO
    TODO: figure out how to parse shit like the finances response
    '''

    s = authenticate('https://s3.as.cmu.edu/sio/index.html')
    s.headers['Content-Type'] = 'text/x-gwt-rpc; charset=UTF-8'

    siojs = s.get('https://s3.as.cmu.edu/sio/sio/sio.nocache.js').content
    permutation = re.search("Rb='([^']+)'", siojs).group(1)

    page_name = 'https://s3.as.cmu.edu/sio/sio/%s.cache.html' % (permutation)
    cachehtml = s.get(page_name).content

    # to successfully do RPC with SIO, you have to find the correct keys
    # for each different kind of RPC you're doing and send them with the request
    def get_key(key):
        var_name = re.search("'%s',(\w+)," % key, cachehtml).group(1)
        return re.search("%s='([^']+)'" % var_name, cachehtml).group(1)

    context_key = get_key('userContext.rpc')
    content_key = get_key('bioinfo.rpc')

    # GWT returns something that's _almost_ JSON but not quite
    def parse_gwt(gwt_response):
        return json.loads(gwt_response.replace("'", '"').replace("\\", "\\\\")[4:])

    return_data = {}

    # info in user context: full name, major/school
    s.post('https://s3.as.cmu.edu/sio/sio/userContext.rpc',
           data=('7|0|4|https://s3.as.cmu.edu/sio/sio/|%s|edu.cmu.s3.ui.common.client.serverproxy.user.UserContextService|initUserContext|1|2|3|4|0|' % context_key))

    # get mailbox/smc
    gwt_response =  s.post('https://s3.as.cmu.edu/sio/sio/bioinfo.rpc',
                           data=('7|0|4|https://s3.as.cmu.edu/sio/sio/|%s|edu.cmu.s3.ui.sio.student.client.serverproxy.bio.StudentBioService|fetchStudentSMCBoxInfo|1|2|3|4|0|' % content_key)).content
    sio_json = parse_gwt(gwt_response)

    return_data['smc'] = sio_json[5][2]
    return_data['mailbox_combo'] = sio_json[5][1]

    # get schedule
    now = datetime.now()
    currSemester = ('F' if now.month > 6 else 'S') + str(now.year % 100)
    cal = Calendar.from_string(s.get('https://s3.as.cmu.edu/sio/secure/export/schedule/%s_semester.ics?semester=%s' % (currSemester, currSemester)).content)
    day_map = {'MO': 1, 'TU': 2, 'WE': 3, 'TH': 4, 'FR': 5}
    return_data['schedule'] = []
    for event in cal.walk():
        if event.name != 'VEVENT': continue

        return_data['schedule'].append({
            'days': map(lambda day: day_map[day], event.get('rrule').get('byday')),
            'location': event.get('location').strip(),
            'summary': event.get('summary').strip(),
            'start_time': event.get('dtstart').dt,
            'end_time': event.get('dtend').dt
        })

    return return_data
Beispiel #12
0
 def __init__(self, icsFeed, icsId, gCal, addTo, addedEventsFile, addedEventsList):
     self.iCal = Calendar.from_string(icsFeed)
     self.gCal = gCal
     self.addTo = addTo
     self.icsId = icsId
     self.addedEventsFile = addedEventsFile
     self.addedEventsList = addedEventsList
     self.addedEvents = 0
Beispiel #13
0
    def import_feed(self, feed):
        from molly.apps.feeds.models import Item, vCard

        calendar = Calendar.from_string(urllib2.urlopen(feed.rss_url).read())

        items = set()
        for component in calendar.walk():

            if component.name == 'VEVENT':
                item, created = Item.objects.get_or_create(feed=feed,
                        guid=str(component.get('UID')))
                # Do not create the event if one the property is not correct,
                # first tries to parse DT as datetime then as date, if it still
                # fails, then ignore
                try:
                    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()
                        item.venue = location

                    try:
                        item.last_modified = vDatetime.from_ical(str(
                            component.get('LAST-MODIFIED')))
                    except Exception, e:
                        item.last_modified = datetime.now()

                    item.save()
                    items.add(item)
Beispiel #14
0
    def execute(self, quals, columns):
	ical_file = urllib.urlopen(self.url).read()
	cal = Calendar.from_string(ical_file)
        for v in cal.walk('vevent'):
            e = Event(v)
	    line = {}
            for column_name in self.columns:
                line[column_name] = e.decoded(column_name)
            yield line
Beispiel #15
0
def loadCal(cursor, src):

    if src[:7] == 'http://':
        f = urllib.urlopen(src)
    else:
        f = open(src,'rb')

    cal = Calendar.from_string(f.read())
    added = 0

    for event in cal.walk():

        if event.name == 'VCALENDAR':
            #pass
            pass
        elif event.name == 'VEVENT':
            #store event!
            timediff = round(
                float(
                    (datetime.strptime(str(event['DTEND']),'%Y%m%dT%H%M%SZ') - datetime.strptime(str(event['DTSTART']),'%Y%m%dT%H%M%SZ')).seconds
                ) /60/60,1)
            date = datetime.strptime(str(event['DTEND']),'%Y%m%dT%H%M%SZ').isoformat()
            split = event['summary'].split(":")
            projectname = split[0] if len(split) > 1 else 'xx'
            summary = ":".join(split[1:]) if len(split) > 1 else split[0] 

            sql = '''
                                INSERT INTO event VALUES (
                                    '%s',
                                    '%s',
                                    '%s',
                                    '%s',
                                    %0.2f)
            ''' % (
                                    event['uid'],
                                    date,
                                    projectname,
                                    summary,
                                    timediff
                                    )

            try:
                cursor.execute(sql)
            except sqlite3.IntegrityError:
                continue
            except:
                print sys.exc_info()
                exit()

            added += 1
            print sql

    cursor.connection.commit()
    cursor.connection.close
    f.close()
    return added
 def loadIcalSourceFile( self ):
     try:
         if self._icalfile != "":
             cal = Calendar.from_string(open(self._icalfile,'rb').read())
             self._entries =[]
             for component in cal.walk('vevent'):
                 if component['summary'].strip().lower() == 'vacation:all':
                     self.addVacation(component)  
     except Exception, ex:
         self._log.exception(ex)
    def _get_ical(self, ics):
        if hasattr(Calendar, 'from_ical'):
            cal = Calendar.from_ical(ics)
        elif hasattr(Calendar, 'from_string'):
            cal = Calendar.from_string(ics)

        for e in cal.walk():
            if e.name == "VEVENT":
                return e

        return None
Beispiel #18
0
def AddOrUpdateWebcal(webcal):
	calString = urllib.urlopen(webcal.webcal_url).read()
	cal = VCALENDAR.from_string(calString)
	eventCluster = EventCluster(
			cluster_title = webcal.webcal_title,
			cluster_description = webcal.webcal_description,
			cluster_user_created = webcal.webcal_user_added,
			cluster_rsvp_enabled = False,
			cluster_board_enabled = True,
			cluster_notify_boardpost = False,
		)
Beispiel #19
0
 def readEvents(self):
     self.events = []
     self.timezones = {}
     parser = Calendar.from_string(self.raw_data)
     tzs = parser.walk("vtimezone")
     self.parseTzs(tzs)
     events = parser.walk("vevent")
     for event in events:
         res = self.parseEvent(event)
         if res:
             self.events.append(res)
    def _get_ical(self, ics):
        if hasattr(Calendar, 'from_ical'):
            cal = Calendar.from_ical(ics)
        elif hasattr(Calendar, 'from_string'):
            cal = Calendar.from_string(ics)

        for e in cal.walk():
            if e.name == "VEVENT":
                return e

        return None
Beispiel #21
0
    def findMonthEvts(self, dayList, listCalendar):

        #Define the start and end limit
        start = dayList[0]
        end = dayList[-1]

        month_evt = {}

        for n, calendar in enumerate(listCalendar):

            if calendar['activate'] == "true":
                start_date = '%04d%02d%02d' % (start['year'], start['month'],
                                               start['number'])
                end_date = '%04d%02d%02d' % (end['year'], end['month'],
                                             end['number'])

                print n, calendar

                if calendar['typeaccount'] == "google":
                    start_date = '%04d-%02d-%02d' % (
                        start['year'], start['month'], start['number'])
                    end_date = '%04d-%02d-%02d' % (end['year'], end['month'],
                                                   end['number'])
                    events = self.googleCalendar.return_calendar_events(
                        calendar['login'], calendar['password'],
                        calendar['url'], start_date, end_date)

                    for e in events:
                        month_evt[e] = "event"

                elif calendar['typeaccount'] == "local":
                    #Traitment of the local iCalendar File
                    url = translatePath(calendar['url'])
                    cal = Calendar.from_string(
                        open(os.path.join(url), 'rb').read())

                    for evt in cal.walk('VEVENT'):
                        a = '%04d%02d%02d' % (
                            vDatetime.from_ical(evt['dtstart'].ical()).year,
                            vDatetime.from_ical(evt['dtstart'].ical()).month,
                            vDatetime.from_ical(evt['dtstart'].ical()).day)

                        if a >= start_date and a <= end_date:

                            month_evt[a] = "event"

                elif calendar['typeaccount'] == "web":
                    pass

        return month_evt
Beispiel #22
0
def readICal(filename):
	from icalendar import Calendar, Event
	l = []
	#extract data from calendar
	cal = Calendar.from_string(open(path.expanduser(filename),'rb').read())
	for comp in cal.walk():
	#	print comp
		try:	comment = comp['comment'].pop()
		except:	comment = ''
		try:
			if re.match('^%s' % parsed.prefix, comp['summary']):
				l.append([datetime.strptime(str(comp['dtstart']), '%Y%m%dT%H%M%S'), datetime.strptime(str(comp['dtend']), '%Y%m%dT%H%M%S') + timedelta(seconds=59), comp['summary'], comment])
		except:	pass
	return l
Beispiel #23
0
def parse_cal(url):
    data = urllib.urlopen(url).read()
    cal = Calendar.from_string(data)
    
    an_hour_ago = to_local(datetime.datetime.now() - datetime.timedelta(hours=1))

    events = []
    for ev in cal.walk():
        if ev.name == 'VEVENT':
            start = to_local(parse(str(ev['dtstart'])))
            if start.time() and start >= an_hour_ago and ev['LOCATION']:
                events.append(make_dict(ev))
    
    return events
Beispiel #24
0
    def handle(self, *args, **options):
        files = map(lambda x: open(x, 'r'), args)
        if len(args) == 0:
            import sys
            files.append(sys.stdin)
        for ical_file in files:
            try:
                ical_string = ical_file.read()
                cal = Calendar.from_string(ical_string)
                for component in cal.walk():
                    if component.name == "VEVENT":
                        summary = component.decoded('summary')
                        try:
                            start = component.decoded('dtstart')
                        except:
                            start = None
                        location = component.decoded('location')
                        tournament = options['tournament']
                        r_compiled = re.compile(u'^(?P<team1>[A-záéíóú´\'\(\)\. ]+)(?P<team1_score>[0-9]*) v[s\.]* (?P<team2>[A-záéíóú´\'\(\)\. ]+)(?P<team2_score>[0-9]*).*$')
                        r = r_compiled.match(summary)
                        team1 = r.group('team1').strip()
                        team2 = r.group('team2').strip()
                        team1_score = r.group('team1_score').strip() or None
                        team2_score = r.group('team2_score').strip() or None
                        try:
                            team1_instance = Team.objects.get(name=team1)
                        except Team.DoesNotExist as e:
                            team1_instance = Team.objects.create(name=team1)
                        try:
                            team2_instance = Team.objects.get(name=team2)
                        except Team.DoesNotExist as e:
                            team2_instance = Team.objects.create(name=team2)
                        if tournament:
                            try:
                                tournament_instance = Tournament.objects.get(name=tournament)
                            except Tournament.DoesNotExist as e:
                                tournament_instance = Tournament.objects.create(name=tournament)
                        else:
                            tournament_instance = None
                        match = Match(tournament=tournament_instance, start=start, location=location, team1=team1_instance, team2=team2_instance, team1_score=team1_score, team2_score=team2_score)
                        if start:
                            if Match.objects.filter(team1=team1_instance, team2=team2_instance, start__year=start.year, start__month=start.month, start__day=start.day).exists() or Match.objects.filter(team1=team2_instance, team2=team1_instance, start__year=start.year, start__month=start.month, start__day=start.day).exists():
                                self.stdout.write(u'Found previous instance of "%s". Not importing!\n' % match)
                                continue
                        match.save()

            except Exception as e:
                raise CommandError(e)
        self.stdout.write(u'Successfully imported calendar\n')
Beispiel #25
0
 def get_recurrence_data(self):
     r = {}
     c = iCal.from_string("BEGIN:EVENT\n%sEND:EVENT" % self._event.recurrence.text)
     r['DTSTART']=c['DTSTART'].dt
     r['DTEND']=c['DTEND'].dt
     r['FREQ']=c['RRULE']['FREQ'][0]
     if c['RRULE'].has_key('WKST'):
         r['WKST']=c['RRULE']['WKST'][0]
     if c['RRULE'].has_key('UNTIL'):
         r['UNTIL']=c['RRULE']['UNTIL'][0].astimezone(LocalTimezone())
     if c['RRULE'].has_key('BYDAY'):
         r['BYDAY']=c['RRULE']['BYDAY']
     if c['RRULE'].has_key('INTERVAL'):
         r['INTERVAL']=c['RRULE']['INTERVAL'][0]
     return r
Beispiel #26
0
def parse_cal(url):
    data = urllib.urlopen(url).read()
    cal = Calendar.from_string(data)

    an_hour_ago = to_local(datetime.datetime.now() -
                           datetime.timedelta(hours=1))

    events = []
    for ev in cal.walk():
        if ev.name == 'VEVENT':
            start = to_local(parse(str(ev['dtstart'])))
            if start.time() and start >= an_hour_ago and ev['LOCATION']:
                events.append(make_dict(ev))

    return events
 def demarshall(self, instance, data, **kw):
     file = kw.get('file', None)
     if file is not None:
         if not data:
             data = file.read()
     calendars = iCalendar.from_string(data, multiple=True)
     do_action = kw.get('do_action', True)
     kw_map = default_mapping
     for klass, mapping in kw_mappings:
         if isinstance(instance, klass):
             kw_map = mapping
     for calendar in calendars:
         for ev in calendar.walk('VEVENT'):
             # We only care about the first one here.
             set_event_info_from_vevent(instance, ev, kw_map,
                                        do_action=do_action)
             break
Beispiel #28
0
def AddOrUpdateWebcal(webcal):
	calString = urllib.urlopen(webcal.webcal_url).read()
	cal = VCALENDAR.from_string(calString)
	eventCluster = EventCluster(
			cluster_title = webcal.webcal_title,
			cluster_description = webcal.webcal_description,
			cluster_user_created = webcal.webcal_user_added,
			cluster_category = webcal.webcal_default_category,
			cluster_rsvp_enabled = False,
			cluster_board_enabled = True,
			cluster_notify_boardpost = False,
		)
	eventCluster.save()
	
	for component in cal.walk():
		if(component.name == 'VEVENT'):
			valid = True
			proplist = {}
			REQ_PROPS = ('UID','SUMMARY','DTSTART','DTEND')
			for prop in component.property_items():
				proplist[prop[0]] = prop[1]

			for rprop in REQ_PROPS:
				if rprop not in proplist:
					print 'MISSING %s' % rprop
					valid = False

			if valid:
				try:
					updateEvent = Event.objects.get(event_webcal_uid = proplist['UID'])
					print 'I found my old friend, %s' % proplist['UID']
				except:
					dtstart = vDDDTypes.from_ical(proplist['DTSTART'].ical())
					dtend = vDDDTypes.from_ical(proplist['DTEND'].ical())
					add_event = Event(
						event_webcal_uid = proplist['UID'],
						event_user_last_modified = CalUser.objects.get(user_netid='yaro'),
						event_subtitle = proplist['SUMMARY'],
						event_subdescription = proplist.get('DESCRIPTION','No description provided.'),
						event_date_time_start = dtstart,
						event_date_time_end = dtend,
						event_location_details = proplist.get('LOCATION',''),
						event_cluster = eventCluster,
						event_cancelled = False,
						event_attendee_count = 0,)
					add_event.save()
Beispiel #29
0
def main(argv):
    # TODO: specify filename?
    cal_str = open('ical.ics').read()
    cal = Calendar.from_string(cal_str)

    vevents = (ev for ev in cal.walk() if ev.name == 'VEVENT')
    current_vevents = current_events_for_vevents(vevents)
    event_datas = (data_for_vevent(ev) for ev in current_vevents)

    ordered_event_data = sorted(event_datas, key=lambda d: d[0])

    with open('giants_schedule.py', 'w') as outfile:
        outfile.write('import datetime\n\n\n')
        outfile.write('schedule = ')
        outfile.write(pformat(tuple(ordered_event_data)))

    return 0
Beispiel #30
0
    def nextmeeting(self, channel, user):
        import requests
        from icalendar import Calendar
        from dateutil import tz
        import datetime
        DATE_FORMAT = "%B %d, %Y @ %-I:%M %p"
        DATE_FORMAT_NO_TIME = "%B %d, %Y @ All Day"

        ics = requests.get(
            "https://www.google.com/calendar/ical/outofthemadness%40gmail.com/public/basic.ics"
        )
        events = []
        cal = Calendar.from_string(ics)

        for event in cal.walk('vevent'):
            to_zone = tz.gettz("America/New_York")
            date = event.get("dtstart").dt
            date_format = DATE_FORMAT
            if hasattr(date, "astimezone"):
                date = event.get("dtstart").dt.satimezone(to_zone)
            else:
                date_format = DATE_FORMAT_NO_TIME

            description = event.get("description", "")
            summary = event.get("summary", "")
            location = event.get("location", "")
            if not location:
                location = "TBA"

            events.append({
                "real_date": date,
                "start": date.strftime(date_format),
                "description":
                description if description else "No Description",
                "summary": summary,
                "location": location
            })

            sorted_events = sorted(events,
                                   key=lambda k: k["real_date"],
                                   reverse=True)
            next_meeting = [
                x for x in sorted_events
                if x["real_date"].date() >= datetime.date.today()
            ][0]
    def demarshall(self, instance, data, **kw):
        file = kw.get('file', None)
        if file is not None:
            if not data:
                data = file.read()
        calendars = iCalendar.from_string(data, multiple=True)
        do_action = kw.get('do_action', True)
        items = kw.get('items', [])

        title = None
        for calendar in calendars:
            if title is None:
                for cal in calendar.walk('VCALENDAR'):
                    title = cal.get('x-wr-calname', None)  # Apple's iCal Title
                    if title is not None:
                        title = convert(title)
                        break
            for ev in calendar.walk('VEVENT'):
                # We figure out the mapping after the first one has been
                # created, or at least one exists.
                id = generateId(ev, context=instance)
                event = instance._getOb(id, default=None)
                created = False

                if event is None:
                    instance.invokeFactory('Event', id)
                    event = instance._getOb(id)
                    created = True
                items.append((id, event))
                # Detect kw_map to use. Can be different for different
                # kinds of events in the same calendar. That's a fairly
                # cornerish case though.
                kw_map = None
                for klass, mapping in kw_mappings:
                    if isinstance(event, klass):
                        kw_map = mapping
                if kw_map is None:
                    kw_map = default_mapping
                set_event_info_from_vevent(event,
                                           ev,
                                           kw_map,
                                           do_action=do_action)

                if created:
                    notify(ObjectInitializedEvent(event))
 def demarshall(self, instance, data, **kw):
     file = kw.get('file', None)
     if file is not None:
         if not data:
             data = file.read()
     calendars = iCalendar.from_string(data, multiple=True)
     do_action = kw.get('do_action', True)
     kw_map = default_mapping
     for klass, mapping in kw_mappings:
         if isinstance(instance, klass):
             kw_map = mapping
     for calendar in calendars:
         for ev in calendar.walk('VEVENT'):
             # We only care about the first one here.
             set_event_info_from_vevent(instance,
                                        ev,
                                        kw_map,
                                        do_action=do_action)
             break
    def demarshall(self, instance, data, **kw):
        file = kw.get('file', None)
        if file is not None:
            if not data:
                data = file.read()
        calendars = iCalendar.from_string(data, multiple=True)
        do_action = kw.get('do_action', True)
        items = kw.get('items', [])

        title = None
        for calendar in calendars:
            if title is None:
                for cal in calendar.walk('VCALENDAR'):
                    title = cal.get('x-wr-calname', None) # Apple's iCal Title
                    if title is not None:
                        title = convert(title)
                        break
            for ev in calendar.walk('VEVENT'):
                # We figure out the mapping after the first one has been
                # created, or at least one exists.
                id = generateId(ev, context=instance)
                event = instance._getOb(id, default=None)
                created = False
                
                if event is None:
                    instance.invokeFactory('Event', id)
                    event = instance._getOb(id)
                    created = True
                items.append((id, event))
                # Detect kw_map to use. Can be different for different
                # kinds of events in the same calendar. That's a fairly
                # cornerish case though.
                kw_map = None
                for klass, mapping in kw_mappings:
                    if isinstance(event, klass):
                        kw_map = mapping
                if kw_map is None:
                    kw_map = default_mapping		
                set_event_info_from_vevent(event, ev, kw_map, do_action=do_action)
                
                if created:
                    notify(ObjectInitializedEvent(event))                
Beispiel #34
0
 def post(self):
     textToParse = urlfetch.fetch(self.request.get('url'))
     parsed = BeautifulSoup(textToParse.content)
     icsUrls = parsed.findAll(href=re.compile(".*.ics"))
     if len(icsUrls) == 0:
         self.response.out.write("Did not found .ics links")
     else:
         takeFirst = icsUrls[0]
         iCalContent = urlfetch.fetch(takeFirst['href']).content
         parsedICal = Calendar.from_string(iCalContent).walk()
         vCalendar = parsedICal[0]
         vEvent = parsedICal[1]
         self.response.out.write("Name:" + vCalendar['X-WR-CALNAME']) 
         self.response.out.write("<br/>") 
         self.response.out.write("When:" + str(vEvent['DTSTART'])) 
         self.response.out.write("<br/>") 
         self.response.out.write("Where:" + vEvent['LOCATION']) 
         self.response.out.write("<br/>") 
         self.response.out.write("More Info:" + vCalendar['X-ORIGINAL-URL']) 
         self.response.out.write("<br/>") 
         self.response.out.write("Description:" + vEvent['DESCRIPTION']) 
Beispiel #35
0
 def findMonthEvts(self, dayList, listCalendar):
     
     #Define the start and end limit
     start = dayList[0]
     end = dayList[-1]
 
     month_evt={}
   
     for n,calendar in enumerate(listCalendar) :
     
         if calendar['activate'] == "true" :
             start_date = '%04d%02d%02d' % (start['year'],start['month'],start['number'])
             end_date = '%04d%02d%02d' % (end['year'],end['month'],end['number'])
     
             print n, calendar
             
             if calendar['typeaccount'] == "google" :
                 start_date = '%04d-%02d-%02d' % (start['year'],start['month'],start['number'])
                 end_date = '%04d-%02d-%02d' % (end['year'],end['month'],end['number'])
                 events = self.googleCalendar.return_calendar_events(calendar['login'], calendar['password'], calendar['url'], start_date, end_date)
                 
                 for e in events :
                     month_evt[e] = "event"
             
             elif calendar['typeaccount'] == "local" :
                 #Traitment of the local iCalendar File
                 url = translatePath ( calendar['url'] )
                 cal = Calendar.from_string(open(os.path.join(url),'rb').read())
                 
                 for evt in cal.walk('VEVENT'):
                     a = '%04d%02d%02d' % (vDatetime.from_ical(evt['dtstart'].ical()).year,vDatetime.from_ical(evt['dtstart'].ical()).month,vDatetime.from_ical(evt['dtstart'].ical()).day)
                     
                     if a >= start_date and a <= end_date:
                     
                         month_evt[a] = "event"
             
             elif calendar['typeaccount'] == "web" :
                 pass
           
     return month_evt
Beispiel #36
0
    def nextmeeting(self, channel, user):
        import requests
        from icalendar import Calendar
        from dateutil import tz
        import datetime
        DATE_FORMAT = "%B %d, %Y @ %-I:%M %p"
        DATE_FORMAT_NO_TIME = "%B %d, %Y @ All Day"

        ics = requests.get(
            "https://www.google.com/calendar/ical/outofthemadness%40gmail.com/public/basic.ics")
        events = []
        cal = Calendar.from_string(ics)

        for event in cal.walk('vevent'):
            to_zone = tz.gettz("America/New_York")
            date = event.get("dtstart").dt
            date_format = DATE_FORMAT
            if hasattr(date, "astimezone"):
                date = event.get("dtstart").dt.satimezone(to_zone)
            else:
                date_format = DATE_FORMAT_NO_TIME

            description = event.get("description", "")
            summary = event.get("summary", "")
            location = event.get("location", "")
            if not location:
                location = "TBA"

            events.append({
                "real_date": date,
                "start": date.strftime(date_format),
                "description": description if description else "No Description",
                "summary": summary,
                "location": location
                })

            sorted_events = sorted(events, key=lambda k: k["real_date"], reverse=True)
            next_meeting = [x for x in sorted_events if x["real_date"].date() >= datetime.date.today()][0]
Beispiel #37
0
	def post(self):
		try:
			# fetch the ical file and initialize a calendar
			ics_url = self.request.get("ics_url")
			schema = urlfetch.fetch(ics_url, deadline=20).content
			cal = Calendar.from_string(schema)
			
			# find the unique course names
			course_names = set()
			for component in cal.walk():
				if not isinstance(component, Event):
					continue
				
				# guessed course name
				summary = component.decoded('summary', 'none')
				course_names.add(id_from_summary(summary))

			# reply with list of unique course names
			path = os.path.join(os.path.dirname(__file__), '../templates/create.html')
			self.response.out.write(template.render(path, {'course_names':course_names, 'ics_url':ics_url}))
		except (ValueError, InvalidURLError), e:
			path = os.path.join(os.path.dirname(__file__), '../templates/error.html')
			self.response.out.write(template.render(path, {'error_msg':'Oops, the URL you entered was malformed.'}))
Beispiel #38
0
from icalendar import Calendar
from PyRSS2Gen import RSSItem, RSS2
import re,urllib,feedparser

ICAL_URL = 'http://www.pogdesign.co.uk/cat/download_ics/dd1cc774b062db1df0a594402f3ac10b'

url = urllib.urlopen(ICAL_URL)

cal = Calendar.from_string(url.read())
events = cal.walk('VEVENT')

p = re.compile('(.*) Episodes, TV Shows')

series = []
for event in events:
    serie = event.get('CATEGORIES')
    serie = p.match(serie).groups()[0].strip()
    series.append(serie)

series = list(set(series))
print series

# generate the rss urls
hit_list = []
for name in series:
    name = urllib.quote(name)
    feed = feedparser.parse('http://ezrss.it/search/index.php?show_name=%s&quality=720p&mode=rss'%name)
    if len(feed['items'])==0:
            feed = feedparser.parse('http://ezrss.it/search/index.php?show_name=%s&mode=rss'%name)
    print feed.url
    hit_list.append(feed)
Beispiel #39
0

def uid_sort(a, b):
    # fixme: we could protect us here against (invalid) UID-less components
    a_val = get_key_value(a)
    b_val = get_key_value(b)

    if a_val > b_val:
        return 1
    elif a_val < b_val:
        return -1
    else:
        return 0


if len(sys.argv) < 3:
    print "Usage: sort_ics.py in.ics out.ics"
    sys.exit(1)

cal = Calendar.from_string(open(sys.argv[1], 'rb').read())

cal.subcomponents.sort(uid_sort)

# print comps
# comps.sort(uid_sort)
# print comps

f = open(sys.argv[2], 'wb')
f.write(cal.as_string())
f.close()
Beispiel #40
0
    "H to WW Spin Editorial Board",
    "HSG3 properties meeting",
    "SMU",
    "Manchester-UCL-Heidelberg VBF/VBS meeting",
    "VBS W(lnu)V(jj)jj informal meeting",
    "Heavy Ion Trigger Menu Forum",
]
# ADD YOUR KEYWORDS HERE ---------------------------------------------------------

#=================================================================================
# code starts here
#=================================================================================

from icalendar import Calendar, Event

rawcal = Calendar.from_string(open('rawcal.ics', 'rb').read())
newcal = Calendar()
print '==================== These are the list of all meetings dl\'ed ========================'
for component in rawcal.walk():
    try:
        isadd = False
        for inkey in includekeyword:
            if component.get('summary').find(inkey) != -1:
                isexclude = False
                for exkey in excludekeyword:
                    #print exkey, component.get('summary'), component.get('summary').find(exkey)==-1
                    if component.get('summary').find(exkey) != -1:
                        isexclude = True
                if not isexclude:
                    isadd = True
        if isadd:
Beispiel #41
0
# Check to see if the file exists (possible race condition)
#if not os.path.isfile(file_name):
#    file(file_name, 'w').close()

# Open the file for writing, download the ical and save it locally
#f = open(file_name, 'r+')
u = urllib2.urlopen(cal_location)
data = u.read()
#f.write(data)

# There should be some checking here to see if the calendars have changed
# but Google update the DTSTAMP every time the ical is downloaded so any
# hash checking will fail

# Create an Calendar from the ical data
cal = Calendar.from_string(data)

# Get the current date/time UTC style
now = datetime.now(pytz.utc)

# Go over all the entries
for c in cal.walk():
    # If it's a VFREEBURY entry then check it out
    if c.name == "VEVENT":
        # Get the starting time and make sure that it's a datetime instance
        # and it's in the future
        dtstart = str(c['dtstart'])
        ds = vDDDTypes.from_ical(dtstart)

        if(isinstance(ds, datetime)) and (ds > now):
            # Start 30 minutes before the live stream is meant to start
# Parses groups.drupal.org iCal feed and adds content from individual events.

import scraperwiki
import lxml.html
from icalendar import Calendar, Event

# Variables
data = []

# Get main iCal feed
ical = scraperwiki.scrape('http://groups.drupal.org/ical')
cal = Calendar.from_string(ical)

# Go through events
for component in cal.walk('vevent'):
    #print dir(component)
    #print component.values()
    #print component['url']

    # Get full descritpion from event node.
    node = scraperwiki.scrape(component['url'])
    node_dom = lxml.html.fromstring(node)
    node_content = node_dom.cssselect("div.node div.content")

    # Create row.
    add = {
        'uid': component['uid'],
        'url': component['url'],
        'description': node_content[0].text_content()
    }
    data.append(add)
Beispiel #43
0
newcal.add('prodid', '-//' + MY_NAME + '//' + MY_DOMAIN + '//')
newcal.add('version', '2.0')
newcal.add('x-wr-calname', CALENDARNAME)
DEBUGMSG += 'new calendar ' + ICS_OUT + ' started\n'

# we need to add a timezone, because some clients want it (e.g. sunbird 0.5)
newtimezone = Timezone()
newtimezone.add('tzid', OUR_TIMEZONE)
newcal.add_component(newtimezone)

# Looping through the existing calendarfiles
for s in glob.glob(CALDIR + '*.ics'):
    try:
        # open the file and read it
        calfile = open(s, 'rb')
        cal = Calendar.from_string(calfile.read())
        DEBUGMSG += 'reading file ' + s + '\n'
        # every part of the file...
        for component in cal.subcomponents:
            # ...which name is VEVENT will be added to the new file
            if component.name == 'VEVENT':
                try:
                    if HISTORY_DAYS > 0:
                        eventStart = component.decoded('dtstart').strftime(
                            '%Y%m%d')
                        if eventStart < limit:
                            eventId = str(component['dtstart']) + ' | ' + str(
                                component['dtend']) + ' | ' + str(
                                    component['summary'])
                            DEBUGMSG += '  skipped historic event before ' + limit + ' : ' + eventId + '\n'
                            continue
Beispiel #44
0
# Download ics calendar
url = 'https://example.com/calendar.ics'  # TODO: Update!
PathandTitle = '/tmp/snct.ics'
response = urllib2.urlopen(url)
inputCal = response.read()


today = datetime.date.today()
# for debug
#today = datetime.date(2017,4,26)
nextday = today + datetime.timedelta(days=1)

todaySchedules = [ ]
nextdaySchedules = [ ]

cal = Calendar.from_string(inputCal)
body = ""
for ev in cal.walk():
    if ev.name == 'VEVENT':
        start_dt = ev.decoded("dtstart")
        end_dt = ev.decoded("dtend")
        summary = ev['summary'].encode('utf-8')
        # print "{start} - {end} : {summary}".format(start=start_dt.strftime("%Y/%m/%d %H:%M"), end=end_dt.strftime("%Y/%m/%d %H:%M"), summary=summary)

        start_date = datetime.date(int(start_dt.strftime("%Y")),int(start_dt.strftime("%m")),int(start_dt.strftime("%d")))
        end_date = datetime.date(int(end_dt.strftime("%Y")), int(end_dt.strftime("%m")),int(end_dt.strftime("%d")))

        end_date -= datetime.timedelta(days=1)
        if start_date<=today:
            if today<=end_date:
                todaySchedules.append("{start} - {end} : {summary}".format(start=start_dt.strftime("%Y/%m/%d %H:%M"), end=end_dt.strftime("%Y/%m/%d %H:%M"), summary=summary))