def calendar(conf): rdv = "" req = urllib.urlopen(conf["calendar"]["url"]) gcal = Calendar.from_ical(req.read()) i = 0 for component in gcal.walk(): if component.name == "VEVENT": if type(vDDDTypes.from_ical(component.get('dtstart'))) == type( date.today()): start = vDDDTypes.from_ical(component.get('dtstart')) end = vDDDTypes.from_ical(component.get('dtend')) elif type(vDDDTypes.from_ical(component.get('dtstart'))) == type( datetime.today()): start = vDDDTypes.from_ical(component.get('dtstart')).date() end = vDDDTypes.from_ical(component.get('dtend')).date() if date.today() >= start and date.today() <= end: if type(vDDDTypes.from_ical(component.get('dtstart'))) == type( datetime.today()): rdv += "A ".encode("utf-8") + vDDDTypes.from_ical( component.get('dtstart')).strftime( "%H heures %M").encode("utf-8").replace( "0", "") + ", ".encode("utf-8") rdv += component.get("summary").encode("utf-8") + ", ".encode( "utf-8") i += 1 return (i, rdv)
def calendar (conf) : rdv = "" req = urllib.urlopen(conf["calendar"]["url"]) gcal = Calendar.from_ical(req.read()) i = 0 for component in gcal.walk(): if component.name == "VEVENT" : if type(vDDDTypes.from_ical(component.get('dtstart'))) == type(date.today()) : start = vDDDTypes.from_ical(component.get('dtstart')) end = vDDDTypes.from_ical(component.get('dtend')) elif type(vDDDTypes.from_ical(component.get('dtstart'))) == type(datetime.today()) : start = vDDDTypes.from_ical(component.get('dtstart')).date() end = vDDDTypes.from_ical(component.get('dtend')).date() if date.today() >= start and date.today() <= end : if type(vDDDTypes.from_ical(component.get('dtstart'))) == type(datetime.today()) : rdv += "A ".encode("utf-8") + vDDDTypes.from_ical(component.get('dtstart')).strftime("%H heures %M").encode("utf-8").replace("0","") + ", ".encode("utf-8") rdv += component.get("summary").encode("utf-8") + ", ".encode("utf-8") i += 1 return (i, rdv)
# 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 early = ds - timedelta(minutes=30) dtend = str(c['dtend']) de = vDDDTypes.from_ical(dtend) # Finish 90 minutes after the stream is meant to finish late = de + timedelta(minutes=90) # Get the duration of the stream dur = late - early # Example crontab entry to record the stream
description="Script to convert ics to remind format") p.add_argument("--file", "-f", help="file to convert") return p.parse_args() input = args() file_to_convert = str(input.file) g = open(file_to_convert) gcal = Calendar.from_ical(g.read()) remcal = "" for entry in gcal.walk('VEVENT'): if entry.get('summary'): try: event_name = entry.get('summary') event_start_raw = str(vDDDTypes.from_ical(entry.get('dtstart'))) # print( event_start_raw ) event_start = datetime.strptime(event_start_raw[:-6], '%Y-%m-%d %H:%M:%S') # print( event_start ) month = str(calendar.month_abbr[event_start.month]) day = str(event_start.day) year = str(event_start.year) hour = str(event_start.hour) minute = str(event_start.minute) if minute == "0": minute = "00" remcal += "REM " + month + " " + day + " " + year + " +0 AT " + hour + ":" + minute + " +" + time_ahead + " *" + reminder_interval + " SCHED _sfun MSG %a %3 %" + '"' + str( event_name) + '"' + "% \n" with open('remtest', 'w+') as f: f.write(remcal)
def xs_duration2timedelta(dur): d = vDDDTypes.from_ical(dur) return d
def parseFeed(feed, event_type): #f = '%Y-%m-%d %H:%M:%S+00:00' cal = requests.get(feed) cal.encoding = "utf-8" gcal = Calendar.from_ical(cal.text) for component in gcal.walk(): location = '' #last_modified = '' summary = '' event = None uid = None if component.name == "VEVENT": user = User.objects.get(id=1) #print(user) event_type = EventType.objects.get(event_type=event_type) #print(event_type) if component.get('uid'): uid = component.get('uid') try: lookupEvent = Event.objects.get(uid=uid) #lookupEvent = Event.objects.get(title=event.title, description=event.description, url=event.url, dstart=event.dstart, dend=event.dend, due=event.due, location=event.location) print("Found an existing event and updating it.") except Event.DoesNotExist: lookupEvent = None except Event.MultipleObjectsReturned: print("Found multiple objects. Skipping. Check: " + summary) continue # if the event already exists if lookupEvent: event = lookupEvent else: # otherwise, create a new one event = Event() if uid: print('UID: ' + uid) event.uid = uid if component.get('dtstart'): dtstart = component.get('dtstart') dtstart = str(vDDDTypes.from_ical(dtstart)) #print("Date Start:" + dtstart) # format f is defined at the top of the function event.dstart = dtstart if component.get('dtend'): dtend = component.get('dtend') dtend = str(vDDDTypes.from_ical(dtend)) #print('Date End: ' + dtend) event.dend = dtend if component.get('dtstamp'): dtstamp = component.get('dtstamp') dtstamp = str(vDDDTypes.from_ical(dtstamp)) #print('Date Stamp: ' + dtstamp) if component.get('created'): created = component.get('created') created = str(vDDDTypes.from_ical(created)) #print('Date Created: ' + created) if component.get('due'): due = component.get('due') due = str(vDDDTypes.from_ical(due)) #print('Date Due: ' + due) event.due = due if component.get('summary'): summary = component.get('summary') #print('Summary: ' + summary) event.title = summary if component.get('description'): description = component.get('description') #print('Description: ' + description) event.description = description if component.get('url'): url = component.get('url') #print('URL: ' + url) event.url = url if component.get('location'): location = component.get('location') #print('Location: ' + location) event.location = location if component.get('geo'): geo = component.get('geo') event.lat = geo.latitude event.lon = geo.longitude else: if component.get('location'): geocode = geocoder.google(location) event.lat = geocode.lat event.lon = geocode.lng #print ('Geo Code: ' + str(geocode.lat) + ' , ' + str(geocode.lng)) if component.get('related-to'): related_to = component.get('related-to') #print('RELATED-TO: ' + related_to) event.related_to = related_to #if component.get('last-modified'): # last_modified = component.get('last-modified') # event.last_modified = vDDDTypes.from_ical(last_modified) # print('LAST-MODIFIED: ' + str(vDDDTypes.from_ical(last_modified))) event.user = user event.event_type = event_type event.approved = True #print("Saving...") event.save() print("================================") cal.close()