def generate_calendar_except_break(student: Student) -> Calendar: events = IcsCalendarCase.generate_calendar(student, end_date=datetime.date(2020, 4, 17)).events events.update(IcsCalendarCase.generate_calendar(student, start_date=datetime.date(2020, 4, 27)).events) cal = Calendar() cal.events = events return cal
def __init__(self, fetch_urls: str): if not fetch_urls: raise RuntimeError('Please set FETCH_URLS correctly.') ical = Calendar() for url in map(str.strip, fetch_urls.split(',')): c = self.convert_calender(url) if not ical.events: ical = c else: ical.events = ical.events.union(c.events) self.ical = ical
def get_calendar(request): get_token = request.GET.get('token', '') re_token = re.findall( r'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', get_token) token = re_token[0] if 0 < len(re_token) else None url = 'https://tiss.tuwien.ac.at/events/rest/calendar/personal?token={token}'.format( token=token) response = requests.get(url) if response.status_code == 200: tiss_calendar = Calendar(response.text) tiss_calendar.events = map(strip_subject_id, tiss_calendar.events) return HttpResponse(tiss_calendar, content_type='text/calendar;charset=utf-8') else: return HttpResponse('Invalid Token')
def addCalendar(request, eventID): curEvent = Event.objects.get(uuid= eventID) minDate = curEvent.startDate maxDate = curEvent.endDate requestData = request.POST.copy() uploadedFile = request.FILES['contents'] parsedCalendar = uploadedFile.read() cal = ICSCalendar(parsedCalendar) calendarEvents = cal.events calendarEvents[:] = [x for x in calendarEvents if not (x.begin < minDate or x.end > maxDate)] cal.events = calendarEvents newCalendar = Calendar(username= requestData.pop("name")[0], contents= str(cal), event= curEvent) newCalendar.save() return redirect(curEvent)
def ice_scraper() -> None: load_config_file() # Create our calendar cal = Calendar() cal.events = [] process_practice_schedule(cal) process_game_schedule(cal) # Write the calendar out to a file. if 0 < len(cal.events): try: with open(config['ics_file'], 'w') as f: f.writelines(cal) except PermissionError: print('ERROR: You do not have sufficient permissions to write to', filename) sys.exit()
def convert_calender(self, url: str) -> Calendar: text = requests.get(url).text text = re.sub(r'^X-WR.*?:.*$', '', text, 0, re.MULTILINE) text = re.sub(r'^STATUS:.*$', '', text, 0, re.MULTILINE) text = re.sub(r'^PRODID:(.{,5}).*$', r'PRODID:-//IcalWrapper \1//EN', text, 0, re.MULTILINE) ical = Calendar(text) converted_events = set() for event in ical.events: if event.all_day: event.name = f'[(終日の予定) {event.name}]' event.begin = event.begin.to(self.TIMEZONE).replace(hour=self.BEGIN_HOUR).to('UTC') event.end = event.begin.shift(hours=self.INTERVAL_HOURS) event.created = event.begin event.last_modified = event.begin event.transparent = False event.description = "(終日)" + event.description or "" event.uid = str(uuid4()) converted_events.add(event) ical.events = converted_events return ical
def merge(cals: List[Calendar]) -> Calendar: """Merge a list of calendars into a single calendar Only takes the event into account, not the tasks or the alarms :param cals: the list of calendars to merge :type cals: List[Calendar] :return: the calendar containing the union of the events contained in the cals list :rtype: Calendar :raises ValueError: if an element of the list is not a Calendar """ result = Calendar() for cal in cals: if not isinstance(cal, Calendar): raise ValueError("All elements should be Calendar") result.events = result.events.union(cal.events) return result
def create_ics(events): logger.info('Create ics file: %s', config['core']['ics_output']) calendar = Calendar() calendar.events = events with open(config['core']['ics_output'], 'w') as ics_file: ics_file.writelines(calendar)