Skip to content

Instantly share code, notes, and snippets.

@tjmichael81
Last active March 27, 2018 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjmichael81/2f2e4de271ef1997c9ab811d3ee3efbe to your computer and use it in GitHub Desktop.
Save tjmichael81/2f2e4de271ef1997c9ab811d3ee3efbe to your computer and use it in GitHub Desktop.
Esri Python API Samples
#-------------------------------------------------------------
# Boilerplate connection / authentication
#-------------------------------------------------------------
import arcgis
from arcgis.gis import GIS
# Login credentials
url = "<url to agol or portal>"
username = "<user name>"
password = "<password>"
# Make a connection to the portal
gis = GIS(url=url, username=username, password=password)
#-------------------------------------------------------------
# Print portal members and group membership
#-------------------------------------------------------------
# Query the portal for all org users
portal_users = gis.users.search(query="*")
for user in portal_users:
user_details = gis.users.get(user.username)
# Get user details from response
user_name = user_details.username
user_full_name = user_details.fullName
groups = user_details.groups
group_names = [i.title for i in groups]
group_names.sort()
# Format response for user
resp = user_full_name + "(" + user_name + ")" + "\n"
resp += "Groups: " + ", ".join(group_names) + "\n"
resp += "\n"
# Print response
print(resp)
#-------------------------------------------------------------
# Print item properties
#-------------------------------------------------------------
itemid = "af7568d8579048f7b42e534891824029"
item_object = gis.content.get(itemid)
for i in item_object:
print(i, ":", item_object[i])
#-------------------------------------------------------------
# Print item size
# (Helpful for determining size of tile layer
#-------------------------------------------------------------
itemid = "acb03aa4b0a04c0a831917b64ef4a860"
i = gis.content.get(itemid)
s = i.size
mb = round(s / 1048576, 3)
gb = round(s / 1073741824, 3)
print("{0} is {1} MB, {2} GB".format(i.title, mb, gb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment