-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_org_webmaps.py
63 lines (59 loc) · 2.65 KB
/
get_org_webmaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Returns list of itemid's for web maps in ArcGIS Online or Portal organization
# import modules
import sys
from arcgis.gis import GIS
def get_maps(url, username, password):
"""Generate list of web maps in ArcGIS Online or Portal organization
url = ArcGIS Online or Portal URL
username = username for administrator account for ArcGIS Online or Portal
password = password for administrator account for ArcGIS Online or Portal"""
try:
# list to store webmap items
org_web_maps = []
# login to ArcGIS Online
gis = GIS(url, username, password)
# add message
print(f'logged into {gis}')
print('generating list of users...')
# generate list of users in ArcGIS Online or Portal organization
# update 'max_users' to account for number of users in your organization
org_users = gis.users.search(query=None, sort_field='username', sort_order='asc', max_users=500, outside_org=False, exclude_system=True)
# add message
print('generated list of users')
print('generating list of web maps in organization...')
# loop over users in organization
for user in org_users:
# get items in user's root directory
user_root_items = user.items()
# user's folders
user_folders = user.folders
# get webmaps in user's root directory
for item in user_root_items:
# focus on Web Map items
if item.type == 'Web Map':
# add webmap itemid to list
org_web_maps.append(item.itemid)
# end user's root directory
# loop over user's folders
for folder in user_folders:
# get items in folder
folder_items = user.items(folder=folder['title'])
# get webmap items
for item in folder_items:
# focus on Web Map items
if item['type'] == 'Web Map':
# add webmap item id's to list
org_web_maps.append(item.itemid)
# end user's folders
# add message
print('completed generating list of web maps in organization')
except (Exception, EnvironmentError) as e:
tbE = sys.exc_info()[2]
# Write the line number the error occured to the log file
# TODO: generate file name through code logic
print(f'error at Line {tbE.tb_lineno} in "get_org_webmaps.py')
# Write the error print( to the log file
print(f'error: {str(e)}')
finally:
# return list of itemid's for web maps
return org_web_maps