Last active
December 19, 2015 15:39
-
-
Save oevans/5978035 to your computer and use it in GitHub Desktop.
Draft utility functions for ago-tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def findNewUsers(users,daysToCheck): | |
| newUsers = [] | |
| for user in users: | |
| if date.fromtimestamp(float(user['created'])/1000) > date.today()-timedelta(days=daysToCheck): | |
| newUsers.append(user) | |
| return newUsers | |
| def addUsersToGroups(users,groups): | |
| params = urllib.urlencode({'token' : self.user.token, | |
| 'f' : 'json'}) | |
| for groupID in groups: | |
| for user in users: | |
| user = users['username'] | |
| print 'Attempting to add ' + user + ' to groupID ' + groupID | |
| # Add Users - REQUIRES POST method | |
| response = urllib.urlopen(myAgol.portalUrl + '/sharing/rest/community/groups/' + groupID + '/addUsers?', 'users=' + user + "&" + parameters).read() | |
| print response | |
| # Error checking - print to console | |
| if not 'success' in json.loads(response): | |
| print 'ERROR: ' + user + ' was NOT added to groupID ' + groupID | |
| def findAdmins(users): | |
| adminUsers[] | |
| for user in users: | |
| if users['role'] = 'org_admin': | |
| adminUsers.append(user) | |
| return adminUsers | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment