def to_disapprove(eid, reason): eid = str(eid).strip() service = authorize() deleted_event = service.events().get(calendarId=PENDING_CAL_ID, eventId=eid).execute() update_spreadsheet(eid, eid, 'Disapproved') event_json = created_event_to_json(deleted_event) email_address = deleted_event['attendees'][0]['email'] service.events().delete(calendarId=PENDING_CAL_ID, eventId=eid).execute() send_disapprove_mail(event_json, email_address, reason)
def to_approve(eid): eid = str(eid).strip() service = authorize() updated_event = service.events().move(calendarId=PENDING_CAL_ID, eventId=eid, destination=APPROVED_CAL_ID).execute() update_spreadsheet(updated_event['id'], eid, 'Approved') event_json = created_event_to_json(updated_event) email_address = updated_event['attendees'][0]['email'] send_approve_mail(event_json, email_address)
def get(self): # Get the authorized Http object created by the decorator. http = decorator.http() #credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/devstorage.read_write') #http = credentials.authorize(httplib2.Http(memcache)) # Call the service using the authorized Http object. event = {"end": {"date": "2015-01-14"},"start": {"date": "2015-01-14"},"description": "Prueba"} request = service.events().insert(calendarId='*****@*****.**', body=event).execute(http=http)
def get_pending_events(): service = authorize() events = service.events().list(calendarId=PENDING_CAL_ID).execute()['items'] pending_events = [] for e in events: j = created_event_to_json(e) pending_events.append(j) return pending_events
def generate_date_list(startdate, enddate, starttime, endtime, calendarid): apptStartDate = datetime.datetime.strptime(startdate, '%Y-%m-%d').date() apptStartTime = datetime.datetime.strptime(starttime, '%H:%M').time() apptEndDate = datetime.datetime.strptime(enddate, '%Y-%m-%d').date() apptEndTime = datetime.datetime.strptime(endtime, '%H:%M').time() # td used to increment while loop one day at a time (24 hours) td = datetime.timedelta(hours=24) # store user's requested start time for use in while loop current_date = apptStartDate # empty list to store suggested free dates free_dates = [] #authorization service = authorize() # loop from user's requested start date to end date while current_date <= apptEndDate: # format start and end times for Google Calendar API call start_rfc3339 = datetime_combine_rfc3339(current_date, apptStartTime) print start_rfc3339 end_rfc3339 = datetime_combine_rfc3339(current_date, apptEndTime) print end_rfc3339 event_list = service.events().list(calendarId=APPROVED_CAL_ID, timeMin=start_rfc3339, timeMax=end_rfc3339).execute()['items'] event_list.extend(service.events().list(calendarId=PENDING_CAL_ID, timeMin=start_rfc3339, timeMax=end_rfc3339).execute()['items']) print "o:", event_list # if there are no events given back, then that time is empty # add date to the suggested free time list if not event_list: free_dates.append(current_date) # if the length of the free_dates array has reached 5, then break from loop if len(free_dates) == 5: break # increment current_date by 1 day to continue while loop current_date += td return free_dates
def get(self): # Get the authorized Http object created by the decorator. http = decorator.http() #credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/devstorage.read_write') #http = credentials.authorize(httplib2.Http(memcache)) # Call the service using the authorized Http object. event = { "end": { "date": "2015-01-14" }, "start": { "date": "2015-01-14" }, "description": "Prueba" } request = service.events().insert(calendarId='*****@*****.**', body=event).execute(http=http)
def post(self): client = gdata.spreadsheet.service.SpreadsheetsService() client.debug = True client.email = email client.password = password client.source = 'test client' client.ProgrammaticLogin() # Se comprueba el valor de los radio button if self.request.get('inscripcion') == "inscripcion_si": inscripcion = "Si" else: inscripcion = "No" if self.request.get('diploma') == "diploma_si": diploma = "Si" else: diploma = "No" if self.request.get('tipo') == "tipo_osl": tipo = "OSL" elif self.request.get('tipo') == "tipo_compratido": tipo = "tipo_compratido" else: tipo = "tipo_fuera" #Se crea una nueva fila y se inserta en la hoja de calculo rows = [] tiempo = time.strftime("%c") rows.append({'titulo':cgi.escape(self.request.get('InputName')),'ponente':cgi.escape(self.request.get('InputPonente')),'fecha':tiempo,'inscripcion':inscripcion,'diploma':diploma,'tipo':tipo,'descripcion':cgi.escape(self.request.get('InputDescripcion')),'dia':cgi.escape(self.request.get('dia')),'mes':cgi.escape(self.request.get('mes')),'anio':cgi.escape(self.request.get('anio')),'hora':cgi.escape(self.request.get('hora')),'minuto':cgi.escape(self.request.get('minuto'))}) for row in rows: try: client.InsertRow(row, spreadsheet_key, worksheet_id) except Exception as e: print e # Se introduce el evento en el calendario fecha_evento = ""+self.request.get('anio')+"-"+self.request.get('mes')+"-"+self.request.get('dia') http = decorator.http() event = {"end": {"date": fecha_evento},"start": {"date": fecha_evento},"summary": cgi.escape(self.request.get('InputName')),"description": cgi.escape(self.request.get('InputDescripcion'))} request = service.events().insert(calendarId='*****@*****.**', body=event).execute(http=http) #Se visualiza la tabla de los eventos creados template_values = {} template = JINJA_ENVIRONMENT.get_template('templates/hoja_calculo.html') self.response.write(template.render(template_values))
def create_event_and_log(event, apptRoom, apptContact, apptPeople): service = authorize() created_event = service.events().insert(calendarId=PENDING_CAL_ID, body=event).execute() log = { 'id': str(created_event['id']), 'timestamp': str(datetime.datetime.now()), 'name': str(session['name']), 'matric': str(session['openid'])[-8:], 'room': str(apptRoom), 'purpose': str(created_event['description']), 'starttime': str(created_event['start']['dateTime']), 'endtime': str(created_event['end']['dateTime']), 'email': str(created_event['attendees'][0]['email']), 'phone': str(apptContact), 'people': str(apptPeople), 'status': 'Pending', 'approved_time': 'N/A' } send_alert_mail(log, GROUP_MAIL) to_spreadsheet(log) return created_event
def get_existing_events(existing_start_rfc3339, existing_end_rfc3339): service = authorize() existing_event_list = service.events().list(calendarId=PENDING_CAL_ID, timeMin=existing_start_rfc3339, timeMax=existing_end_rfc3339).execute()['items'] existing_event_list.extend(service.events().list(calendarId=APPROVED_CAL_ID, timeMin=existing_start_rfc3339, timeMax=existing_end_rfc3339).execute()['items']) return existing_event_list