def subscribe(user_id, cal_id): calendar_client = login.adminLogin("2legstudent", user_id) calendar = gdata.calendar.data.CalendarEntry() calendar.id = atom.data.Id(text=cal_id) returned_calendar = calendar_client.InsertCalendarSubscription(calendar)
def addModule(Title, Summary): """Creates a Google Calendar Args: Title: The Calendars name Summary: The description of the calendar """ #for hardcoded password + username calendar_client = login.adminLogin("calendar") Title = "UCC MODULE " + Title # Create the calendar calendar = gdata.calendar.data.CalendarEntry() calendar.title = atom.data.Title(text=Title) calendar.summary = atom.data.Summary(text=Summary) calendar.where.append(gdata.calendar.data.CalendarWhere(value='UCC')) calendar.color = gdata.calendar.data.ColorProperty(value='#333333') calendar.timezone = gdata.calendar.data.TimeZoneProperty(value='UTC') calendar.hidden = gdata.calendar.data.HiddenProperty(value='false') new_calendar = calendar_client.InsertCalendar(new_calendar=calendar) cal_id = new_calendar.id.text #this code can be used if you want cal_id not to include the preamble and consumer key cal_id = string.replace(cal_id, "http://www.google.com/calendar/feeds/default/calendars/", "") DB.CreateModule(cal_id, Title, Summary) return cal_id
def getAllMembers(): """Lists all people in the domain """ client = login.adminLogin("student") Users = client.RetrieveAllUsers() for entry in Users.entry: users_ret.append(entry.title.text + " lastname" + "(" + entry.title.text + "@" + data.CONSUMER_KEY + ")") return users_ret
def getGroupMembers(group_id): client = login.adminLogin() user_list = [] feed = client.RetrieveAllMembers(group_id) for entry in feed.entry: member_id = append(entry.GetMemberId()) member_id = string.replace(member_id, "@jeromakay.com", "") user_list.append(member_id) return member_id
def subscribeGroup(group_id, cal_id): client = login.adminLogin() user_list = [] feed = client.RetrieveAllMembers(group_id) for entry in feed.entry: member_id = entry.GetMemberId() member_id = string.replace(member_id, "@jeromakay.com", "") user_list.append(member_id) for i in user_list: subscribe(i, cal_id)
def deleteGroup(group_id): """Deletes the google groups with the given ID Args: group_id: A name for the group """ #deal with database here DB.DeleteGroup(group_id) #create client object groupClient = login.adminLogin() #delete the group groupClient.DeleteGroup(group_id)
def sync(): gid = "" uid = "" client = login.adminLogin("student") Users = client.RetrieveAllUsers() existing_users = DB.ListUsersUIDs() for entry in Users.entry: name = entry.title.text + " lastname" gid = entry.title.text + "@" + data.CONSUMER_KEY uid = entry.title.text if uid not in existing_users: DB.CreateUser(gid, uid, name)
def addGroupMember (group_id, member_id): """Adds the members to the group Args: group_id: the ID of the group to update members_array: the users to add """ #deal with database here #DB.AddUserToGroup(group_id, member_id) #create client object groupClient = login.adminLogin() #add users to the group groupClient.AddMemberToGroup(group_id, member_id)
def deleteGroupMember (group_id, members_array): """Deletes the members from a group Args: group_id: the ID of the group to update members_array: the users to add """ #deal with database here DB.EditGroup(group_id, new_group_name, new_description, new_group_type) #create client object groupClient = login.adminLogin() #delete users to the group for member_id in members_array: groupClient.RemoveMemberFromGroup(group_id, member_id)
def updateGroup(group_id, new_group_name, new_description='no description given', new_type_id=1, new_email_permission=None): """Updates a google group with the given paramaters Args: group_id: the ID of the group to update group_name: A new name for the group description: A new description for the group type_id: The type of members of the group (eg student, staff) represented by an int (see database documentation) email_permission: Email settings for the group. """ #create client object groupClient = login.adminLogin() #deal with database here DB.EditGroup(group_id, new_group_name, new_description, new_group_type) #change the group details groupClient.UpdateGroup(group_id, new_group_name, new_description, email_permission)
def deleteModule(cal_id): """Deletes a Google Calendar Args: cal_id: The Calendars ID """ cal_id = string.replace(cal_id, "@", "%40") cal_id_2 = "https://www.google.com/calendar/feeds/default/owncalendars/full/" + cal_id #for hardcoded password + username calendar_client = login.adminLogin("calendar") feed = calendar_client.GetOwnCalendarsFeed() for entry in feed.entry: if entry.GetEditLink().href == cal_id_2: calendar_client.Delete(entry.GetEditLink().href) DB.DeleteModule(cal_id)
def createGroup (group_name, description='no description given', type_id=0, email_permission=None): """Creates a Google Group with the given paramaters Args: group_name: A name for the group description: describes the group type_id: The type of members of the group (eg student, staff) represented by an int (see database documentation) email_permission: Email settings for the group. """ #generate hashed id group_id = hashlib.md5(group_name).hexdigest() #deal with database here DB.CreateGroup(group_id, group_name, description, type_id) #create client object groupClient = login.adminLogin() #create the group and add it to the domain groupClient.CreateGroup(group_id, group_name, description, email_permission)
def update(cal_id, Title, Summary): """Deletes a Google Calendar Args: cal_id: The Calendars ID """ cal_id = "https://www.google.com/calendar/feeds/default/owncalendars/full/" + cal_id cal_id = string.replace(cal_id, "@", "%40") #for hardcoded password + username calendar_client = login.adminLogin("calendar") feed = calendar_client.GetOwnCalendarsFeed() for entry in feed.entry: if entry.GetEditLink().href == cal_id: # calendar represents a previously retrieved CalendarEntry entry.title = atom.data.Title(text=Title) entry.summary = atom.data.Summary(text=Summary) updated_calendar = calendar_client.Update(entry)