def process_request(self, req): """Process the request. For ClearSilver, return a (template_name, content_type) tuple, where `template` is the ClearSilver template to use (either a `neo_cs.CS` object, or the file name of the template), and `content_type` is the MIME type of the content. For Genshi, return a (template_name, data, content_type) tuple, where `data` is a dictionary of substitutions for the template. For both templating systems, "text/html" is assumed if `content_type` is `None`. Note that if template processing should not occur, this method can simply send the response itself and not return anything. """ for path, sub in self.ics_paths.items(): if re.match(path, req.path_info): filename = req.path_info.strip('/').replace('/', '.') rss = re.sub(path, sub, req.path_info) rss = req.base_url + rss break else: return # return the rss feed req.send_response(200) req.send_header('Content-Type', 'text/calendar;charset=utf-8') req.send_header('Content-Disposition', 'attachment; filename=%s' % filename) req.end_headers() calendar = iCal(req.write) calendar.from_rss(rss)
def construct_cal(cours, ids_to_delete): """ Take a list of Cours objects and return an ics calendar object. It take care of the filter. """ cal = iCal("My cal", 0.1) lessons = list(set(map((lambda c: c.type + " - " + c.cours), cours))) ids = range(len(lessons)) dico = dict(zip(lessons,ids)) for c in cours: if not (dico[c.type + " - " + c.cours] in ids_to_delete): event = Event() intitule = c.type + " - " + c.cours event['summary'] = intitule d = c.date h = c.heures.start date = iDate(d.y, d.m, d.d, h.h, h.m) event['dtstart'] = date h = c.heures.end date = iDate(d.y, d.m, d.d, h.h, h.m) event['dtend'] = date event['organizer'] = c.prof event['location'] = c.salle # set the uid of this event to the hash of the repr of the object # useful for update/delete, and so on event['uid'] = hash(str(c)) cal.add(event) return cal
def post_daily_rlc_schedule(): # Load RLC calendar cal = iCal(rlc_ical_url) # Get today's date today_str = get_today() # Find rlcs on duty for today rlcs = cal.get_event_summaries(today_str) # Post rlcs on slack if len(rlcs) > 0: formatted_message = "*" + "* | *".join(rlcs) + "*" post_attachment_slack_message(duty_channel, None, formatted_message, "87693b")
def post_daily_duty_schedule(): # Generate Calendar Dictionary # {str : [dict]} # key => date string (ex. "20191208") # value => list of dicts for each event cal = iCal(ical_url) # Get today's date today_str = get_today() # Find duty team for today duty_members = cal.get_event_summaries(today_str) # Post duty team on slack for member in duty_members: parsed_message = parse_for_users(member) formatted_message = "*" + parsed_message + "*" post_attachment_slack_message(duty_channel, None, formatted_message)
elif change_type == "REMOVAL": post_attachment_slack_message( trade_channel, "Calendar event was deleted :rotating_light:", "*~{event_title}~*\n{date}".format( event_title=parse_for_users(event_summary), date=event_date)) # Close file log_file.close() # Main if __name__ == "__main__": # Create calendar ref calendar = iCal(ical_url) # Schedule jobs schedule.every(5).minutes.do(check_for_calendar_updates, calendar) schedule.every().day.at("16:00").do(post_daily_duty_schedule) # Wrap main loop in a try statement try: # Notify Slack that Duty Bot has been activated if not TESTING_MODE: post_slack_message( "#bot-playground", "Duty Bot activated and reporting for duty :salute:") while True: schedule.run_pending()