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
| import os, urllib, urllib2, datetime, arcpy, json | |
| ## ============================================================================== ## | |
| ## function to update a field - basically converts longs to dates for date fields ## | |
| ## since json has dates as a long (milliseconds since unix epoch) and geodb wants ## | |
| ## a proper date, not a long. | |
| ## ============================================================================== ## | |
| def updateValue(row,field_to_update,value): | |
| outputfield=next((f for f in fields if f.name ==field_to_update),None) #find the output field |
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
| /*Header*/ | |
| <style>#header .nav a, .esri #header-controls ul li a, #header_map_newMap.map_nav a.map_nav_link{color: #fff; text-decoration: none;}</style> | |
| /*Header Hover*/ | |
| <style>#header .nav a:hover {color: #26393d; text-decoration: none;}</style> | |
| /*Footer*/ | |
| <style>.esriItemLinks a, .esriItemLinks a:link, .esriItemLinks a:hover, .esriItemLinks a:active, .esriItemLinks a:visited{color: #26393d;}</style> | |
| /* |
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
| #### PART 1 -- GET AND INSPECT TOKEN #### | |
| import urllib | |
| # Replace <USERNAME>, and <PASSWORD> with your ArcGIS Online subscription account credentials | |
| # Using f=pjson for examples/debugging, should use f=json for scripts | |
| username = '<<USERNAME>>' | |
| password = '<<PASSWORD>>' | |
| # parameters = urllib.urlencode({'username':username,'password':password,'client':'requestip','f':'pjson'}) | |
| parameters = urllib.urlencode({'username':username,'password':password,'client':'referer','referer':'http://www.arcgis.com','f':'pjson'}) |
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
| ''' | |
| NOTES: | |
| - See the ArcGIS REST API documentation for supported operations, methods, and syntax: | |
| http://resources.arcgis.com/en/help/arcgis-rest-api/ | |
| - A TOKEN must be passed as parameter in addition to any required inputs for the operation. | |
| - "urllib.urlencode" handles spaces and other special characters in parameters so that valid URLs are constructed. | |
| - "urllib.urlopen" sends the reqest and handles the response. | |
| - Parameters are appended to URL for GET (see Example 1), but passed to "urlopen" for POST (see Example 2). API docs specifiy supported methods for each operation. | |
| - "json.loads" converts string responses to parseable JSON objects. |
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
| # Modify time formatting codes (e.g., "%Y", etc.) as needed using values from table in python docs here: | |
| # http://docs.python.org/2/library/time.html#time.strftime | |
| # Replace <AGO DATE/TIME> with your time value/variable | |
| import time | |
| time.strftime("%Y-%m-%d %I:%M:%S %p (%Z)",time.localtime(<AGO DATE/TIME>/1000)) | |
| # SAMPLE RESULT - '2013-07-31 11:59:33 PM (Eastern Daylight Time)' |
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
| ## Also plan to add a function transferAllItemsBatch which will read in a CSV file of username pairs. | |
| def transferAllItems(self, userFrom, userTo): | |
| ''' | |
| REQUIRES ADMIN ACCESS | |
| Transfer ownership of all items in userFrom's account to userTo's account, keeping same folder names. | |
| Note, does not check for existing folders in userTo's account. | |
| ''' | |
| # userFrom is the account where the content currently resides | |
| # userTo is the account where the content will be transferred |
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, |
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
| ## Admin script for adding new users (those that recently accepted invitations) to a group or groups. | |
| ## This script uses Evan Caldwell's agolTools module available on GitHub here: https://github.com/Esri/ago-tools | |
| import csv, time, urllib, json, datetime | |
| from datetime import date, timedelta | |
| from agolTools import admin | |
| myAgol = admin.admin() | |
| users = myAgol.getUsers() |
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
| function init() { | |
| if (!_jqueryReady) return; | |
| if (!_dojoReady) return; | |
| esri.arcgis.utils.arcgisUrl = SHARINGURL; // ***ADD THIS LINE*** | |
| if (getParameterByName("webmap") != "") { | |
| WEBMAP_ID = getParameterByName("webmap"); | |
| } |
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
| /*In the config section, add the following line above the existing code */ | |
| var SHARINGURL = "http://<YOUR WEB SERVER NAME HERE>/sharing/content/items" ; |