Exemple #1
0
def copy_groups_sample():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    groups = source.groups(q='Administration')
    copied_groups = copy_groups(groups, source, target, 'wmathot')
    for sourceid in copied_groups.keys():
        print 'Copied ' + sourceid + ' to ' + copied_groups[sourceid]
Exemple #2
0
def count_webmap_url_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    urls = []
    for webmap in portal.webmaps():
        urls.extend(webmap.urls(normalize=True))
    url_counts = dict((url, urls.count(url)) for url in urls)
    pprint(url_counts, indent=2)
Exemple #3
0
def create_user_group_item_reports():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    item_fields = ['id', 'title', 'owner', 'numViews']
    items = portal.search(item_fields, sort_field='numViews', sort_order='desc')
    csvfile = csv.writer(open('items-report.csv', 'wb'))
    csvfile.writerow(item_fields)
    for item in items:
        row = [item[field] for field in item_fields]
        csvfile.writerow(row)

    groups_fields = ['id', 'title', 'owner']
    groups = portal.groups(groups_fields)
    csvfile = csv.writer(open('groups-report.csv', 'wb'))
    csvfile.writerow(groups_fields)
    for group in groups:
        row = [group[field] for field in groups_fields]
        csvfile.writerow(row)

    user_fields = ['username', 'fullName', 'email', 'role']
    users = portal.org_users(user_fields)
    csvfile = csv.writer(open('users-report.csv', 'wb'))
    csvfile.writerow(user_fields)
    for user in users:
        row = [user[field] for field in user_fields]
        csvfile.writerow(row)
Exemple #4
0
def print_webmap():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    try:
        webmap = portal.webmap('cb769438c687478e9ccdb8377116ed02')
        pprint(webmap.json(), indent=2, width=120)
    except Exception as e:
        logging.error(e)
Exemple #5
0
def count_webmap_url_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    urls = []
    for webmap in portal.webmaps():
        urls.extend(webmap.urls(normalize=True))
    url_counts = dict((url, urls.count(url)) for url in urls)
    pprint(url_counts, indent=2)
Exemple #6
0
def daily_item_stats():
    portal = Portal('http://www.arcgis.com')
    today = datetime.utcnow()
    weekago = today - timedelta(days=1)
    q = 'modified:[' + portal_time(weekago) + ' TO ' + portal_time(today) + ']'
    results = portal.search(['type', 'count(type)'], q, group_fields=['type'], num=5000)
    pprint(results, indent=2)
Exemple #7
0
def count_tags():
    portal = Portal('http://www.geoplatform.gov')
    results = portal.search(['tags'])
    tags = unpack(results, flatten=True)
    counts = dict((tag, tags.count(tag)) for tag in tags)
    sorted_counts = sorted(counts.iteritems(), key=itemgetter(1), reverse=True)
    pprint(sorted_counts, indent=2)
Exemple #8
0
def count_webmap_item_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    item_ids = []
    for webmap in portal.webmaps():
        item_ids.extend(webmap.item_ids())
    item_id_counts = dict((id, item_ids.count(id)) for id in item_ids)
    pprint(item_id_counts, indent=2)
Exemple #9
0
def count_item_types():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    counts = portal.search(properties=['type', 'count(type)'],
                           group_fields=['type'],\
                           sort_field='count(type)',\
                           sort_order='desc')
    pprint(counts, indent=2)
Exemple #10
0
def copy_user_with_groups_and_items():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    source_owner = source.logged_in_user()['username']
    target_owner = target.logged_in_user()['username']

    # Copy the groups
    groups = source.groups(q='owner:' + source_owner)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    copied_items = copy_user_contents(source, source_owner, target,
                                      target_owner)
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]
        if sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                if id in copied_groups]
            target.share_items(target_owner, [target_item_id], target_group_ids,\
                               sharing['access'] == 'org',\
                               sharing['access'] == 'public')
Exemple #11
0
def create_user_group_item_reports():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    item_fields = ['id', 'title', 'owner', 'numViews']
    items = portal.search(item_fields,
                          sort_field='numViews',
                          sort_order='desc')
    csvfile = csv.writer(open('items-report.csv', 'wb'))
    csvfile.writerow(item_fields)
    for item in items:
        row = [item[field] for field in item_fields]
        csvfile.writerow(row)

    groups_fields = ['id', 'title', 'owner']
    groups = portal.groups(groups_fields)
    csvfile = csv.writer(open('groups-report.csv', 'wb'))
    csvfile.writerow(groups_fields)
    for group in groups:
        row = [group[field] for field in groups_fields]
        csvfile.writerow(row)

    user_fields = ['username', 'fullName', 'email', 'role']
    users = portal.org_users(user_fields)
    csvfile = csv.writer(open('users-report.csv', 'wb'))
    csvfile.writerow(user_fields)
    for user in users:
        row = [user[field] for field in user_fields]
        csvfile.writerow(row)
Exemple #12
0
def copy_items_query():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='h1n1')
    copied_items = copy_items(items, source, target, 'wmathot', 'Copied Items (h1n1)')
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Exemple #13
0
def export_import_content():
    source = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    file_path = 'C:\\temp\\export'
    web_content = source.search(q=portalpy.WEB_ITEM_FILTER)
    save_items(source, web_content, file_path, indent=4)
    load_items(target, file_path)
Exemple #14
0
def count_webmap_item_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    item_ids = []
    for webmap in portal.webmaps():
        item_ids.extend(webmap.item_ids())
    item_id_counts = dict((id, item_ids.count(id)) for id in item_ids)
    pprint(item_id_counts, indent=2)
Exemple #15
0
def count_item_types():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    counts = portal.search(properties=['type', 'count(type)'],
                           group_fields=['type'],\
                           sort_field='count(type)',\
                           sort_order='desc')
    pprint(counts, indent=2)
Exemple #16
0
def count_tags():
    portal = Portal('http://www.geoplatform.gov')
    results = portal.search(['tags'])
    tags = unpack(results, flatten=True)
    counts = dict((tag, tags.count(tag)) for tag in tags)
    sorted_counts = sorted(counts.iteritems(), key=itemgetter(1), reverse=True)
    pprint(sorted_counts, indent=2)
Exemple #17
0
def copy_groups_sample():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    groups = source.groups(q='Administration')
    copied_groups = copy_groups(groups, source, target, 'wmathot')
    for sourceid in copied_groups.keys():
        print 'Copied ' + sourceid + ' to ' + copied_groups[sourceid]
Exemple #18
0
def print_webmap():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    try:
        webmap = portal.webmap('cb769438c687478e9ccdb8377116ed02')
        pprint(webmap.json(), indent=2, width=120)
    except Exception as e:
        logging.error(e)
Exemple #19
0
def export_import_content():
    source = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    file_path = 'C:\\temp\\export'
    web_content = source.search(q=portalpy.WEB_ITEM_FILTER)
    save_items(source, web_content, file_path, indent=4)
    load_items(target, file_path)
Exemple #20
0
def copy_items_query():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='h1n1')
    copied_items = copy_items(items, source, target, 'wmathot',
                              'Copied Items (h1n1)')
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Exemple #21
0
def copy_items_with_related():
    source = Portal('http://dev.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='type:"Web Mapping Application"', num=5)
    copied_items = copy_items(items, source, target, 'wmathot', 'Web Apps 5',  \
                              relationships=['WMA2Code', 'MobileApp2Code'])
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Exemple #22
0
def copy_items_with_related():
    source = Portal('http://dev.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='type:"Web Mapping Application"', num=5)
    copied_items = copy_items(items, source, target, 'wmathot', 'Web Apps 5',  \
                              relationships=['WMA2Code', 'MobileApp2Code'])
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Exemple #23
0
def hide_user():
    portal = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    user_to_hide = 'wmathot'
    portal.update_user(user_to_hide, {'access': 'private'})
    groups = portal.groups(['id'], 'owner:' + user_to_hide)
    for group in groups:
        portal.update_group(group['id'], {'access': 'private'})
    items = portal.search(['id'], 'owner:' + user_to_hide)
    portal.share_items(user_to_hide, items, None, False, False)
Exemple #24
0
def main(argv=None):
    portal1 = Portal('http://portaldev.esri.com')
    portal2 = Portal('http://dev.arcgis.com')
    portal1_items_by_key = get_items_by_key(portal1)
    portal2_items_by_key = get_items_by_key(portal2)
    print_left_only(portal1.hostname, portal1_items_by_key,
                    portal2_items_by_key)
    print_left_only(portal2.hostname, portal2_items_by_key,
                    portal1_items_by_key)
Exemple #25
0
def daily_item_stats():
    portal = Portal('http://www.arcgis.com')
    today = datetime.utcnow()
    weekago = today - timedelta(days=1)
    q = 'modified:[' + portal_time(weekago) + ' TO ' + portal_time(today) + ']'
    results = portal.search(['type', 'count(type)'],
                            q,
                            group_fields=['type'],
                            num=5000)
    pprint(results, indent=2)
Exemple #26
0
def set_home_page_banner():
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    portal.add_resource('custom-banner.jpg',\
                        data='http://www.myterradesic.com/images/header-globe.jpg')
    portal.update_property('rotatorPanels', \
        [{"id":"banner-custom", "innerHTML": "<img src='http://" + portal.hostname +\
        "/sharing/accounts/self/resources/custom-banner.jpg?token=SECURITY_TOKEN' " +\
        "style='-webkit-border-radius:0 0 10px 10px; -moz-border-radius:0 0 10px 10px; " +\
        "-o-border-radius:0 0 10px 10px; border-radius:0 0 10px 10px; margin-top:0; " +\
        "width:960px; height:180px;'/>"}])
Exemple #27
0
def hide_user():
    portal = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    user_to_hide = 'wmathot'
    portal.update_user(user_to_hide, {'access': 'private'})
    groups = portal.groups(['id'], 'owner:' + user_to_hide)
    for group in groups:
        portal.update_group(group['id'], {'access': 'private'})
    items = portal.search(['id'], 'owner:' + user_to_hide)
    portal.share_items(user_to_hide, items, None, False, False)
Exemple #28
0
def average_coverage_by_item_type():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    def avg_area(extents):
        extents = filter(None, extents)
        if extents:
            areas = []
            for e in extents:
                if e: areas.append((e[1][0] - e[0][0]) * (e[1][1] - e[0][1]))
            return sum(area for area in areas) / len(areas)
        return 0
    portal.aggregate_functions['avg_area'] = avg_area
    results = portal.search(['type', 'avg_area(extent)'], group_fields=['type'])
    pprint(results, indent=2)
Exemple #29
0
def copy_user_with_groups_and_items():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    source_owner = source.logged_in_user()['username']
    target_owner = target.logged_in_user()['username']

    # Copy the groups
    groups = source.groups(q='owner:' + source_owner)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    copied_items = copy_user_contents(source, source_owner, target, target_owner)
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]
        if sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                if id in copied_groups]
            target.share_items(target_owner, [target_item_id], target_group_ids,\
                               sharing['access'] == 'org',\
                               sharing['access'] == 'public')
Exemple #30
0
def invite_org_user():
    portal = Portal('http://wittakermathot.maps.arcgis.com', 'wmathot', '***')

    # Prepare the invitations
    invitations = [{
        'fullname': 'James Bond',
        'username': '******',
        'email': '*****@*****.**',
        'role': 'account_user'
    }]

    # Invite users. Log those who werent invited
    not_invited = portal.invite(invitations, 'test1', 'test2')
    if not_invited:
        print 'Not invited: ' + str(not_invited)

    # Accept the invitations and set the user's password to their username
    accepted_count = 0
    for invitation in invitations:
        username = invitation['username']
        for pending_invitation in portal.invitations(['id', 'username']):
            if username == pending_invitation['username']:
                invitation_id = pending_invitation['id']
                new_password = username
                is_reset = portal.reset_user(username, invitation_id,
                                             new_password)
                if is_reset:
                    portal_as_user = Portal('http://www.arcgis.com', username,
                                            new_password)
                    is_accepted = portal_as_user.accept(invitation_id)
                    if is_accepted:
                        accepted_count += 1

    print 'Invited ' + str(
        len(invitations)) + ', Accepted ' + str(accepted_count)
Exemple #31
0
def find_public_content_with_weak_descriptions():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    public_items = portal.search(q='access:public')
    weak_items = []
    for item in public_items:
        snippet = item.get('snippet')
        description = item.get('description')
        thumbnail = item.get('thumbnail')
        if not snippet or not description or not thumbnail or len(snippet) < 20 \
                       or len(description) < 50:
            weak_items.append(item)
    for weak_item in weak_items:
        owner = weak_item['owner']
        email = portal.user(owner)['email']
        print owner + ', ' + email + ', ' + weak_item['id']
Exemple #32
0
def find_hostname_references():
    hostname = 'wh94.fltplan.com'
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_references = []
    url_items = portal.search(['id', 'type', 'url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        if parse_hostname(item['url']) == hostname:
            hostname_references.append((item['id'], item['type'], item['url']))
    webmaps = portal.webmaps()
    for webmap in webmaps:
        urls = webmap.urls(normalize=True)
        for url in urls:
            if parse_hostname(url) == hostname:
                hostname_references.append((webmap.id, 'Web Map', url))
    pprint(hostname_references, indent=2)
Exemple #33
0
def find_hostname_references():
    hostname = 'wh94.fltplan.com'
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_references = []
    url_items = portal.search(['id','type','url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        if parse_hostname(item['url']) == hostname:
            hostname_references.append((item['id'], item['type'], item['url']))
    webmaps = portal.webmaps()
    for webmap in webmaps:
        urls = webmap.urls(normalize=True)
        for url in urls:
            if parse_hostname(url) == hostname:
                hostname_references.append((webmap.id, 'Web Map', url))
    pprint(hostname_references, indent=2)
Exemple #34
0
def find_public_content_with_weak_descriptions():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    public_items = portal.search(q='access:public')
    weak_items = []
    for item in public_items:
        snippet = item.get('snippet')
        description = item.get('description')
        thumbnail = item.get('thumbnail')
        if not snippet or not description or not thumbnail or len(snippet) < 20 \
                       or len(description) < 50:
            weak_items.append(item)
    for weak_item in weak_items:
        owner = weak_item['owner']
        email = portal.user(owner)['email']
        print owner + ', ' + email + ', ' + weak_item['id']
Exemple #35
0
def average_coverage_by_item_type():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    def avg_area(extents):
        extents = filter(None, extents)
        if extents:
            areas = []
            for e in extents:
                if e: areas.append((e[1][0] - e[0][0]) * (e[1][1] - e[0][1]))
            return sum(area for area in areas) / len(areas)
        return 0

    portal.aggregate_functions['avg_area'] = avg_area
    results = portal.search(['type', 'avg_area(extent)'],
                            group_fields=['type'])
    pprint(results, indent=2)
Exemple #36
0
def main(argv=None):
    portal = Portal('http://wittm.esri.com/maps', 'admin', 'esri.agp')
    print_summary(portal)
    print_user_info(portal)
    print_group_info(portal)
    print_item_info(portal)
    print_system_content(portal)
def share_templates(portaladdress, username, password):
    
    # Create portal connection
    portal = Portal(portaladdress, username, password)
    
    print '\nShare web app templates with "AFMI Web Application Templates" group...'
    results = share_default_webapp_templates(portal, portal.logged_in_user()['username'], 'AFMI Web Application Templates')
    if results['success']:
        print '\tDone.'
    else:
        print 'ERROR: {}'.format(results['message'])
    
    print '\nShare web app templates with "AFMI Gallery Templates" group...'
    results = share_default_gallery_templates(portal, portal.logged_in_user()['username'], 'AFMI Gallery Templates')
    if results['success']:
        print '\tDone.'
    else:
        print 'ERROR: {}'.format(results['message'])    
def main():
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    server = ArcGISConnection(
        'http://sampleserver4.arcgisonline.com/ArcGIS/rest/services')
    root = server.post('/', {'f': 'json'})
    register_services(portal, server, root['services'])
    for folder_name in root['folders']:
        folder = server.post('/' + folder_name, {'f': 'json'})
        register_services(portal, server, folder['services'])
Exemple #39
0
def create_demographics_group():
    arcgisonline = Portal('http://www.arcgis.com')
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    owner = portal.logged_in_user()['username']
    items = arcgisonline.search(q='demographics owner:esri ' +
                                WEBMAP_ITEM_FILTER)
    copied_items = copy_items(items, arcgisonline, portal, owner)
    group_id = portal.create_group(
        {
            'title': 'Demographics',
            'access': 'public',
            'tags': 'demographics'
        },
        thumbnail='http://bit.ly/WEaIh5')
    for item_id in copied_items.values():
        portal.share_items(owner, [item_id], [group_id], True, True)
Exemple #40
0
def main():

    # Before executing rest of script, lets check if 7-zip exe exists
    if not os.path.exists(sevenZipExePath):
        print 'ERROR: File path set by "sevenZipExePath" variable (' + \
            sevenZipExePath + ') does not exist. Exiting script.'
        sys.exit(exitErrCode)

    # Check arguments
    results = check_args()
    if not results:
        sys.exit(exitErrCode)
    server, port, adminuser, password, doCopy, targetFolder, users = results

    if debug:
        print server, port, adminuser, password, doCopy, targetFolder, users

    # Determine where admins upload folder is located on server
    uploadsFolderInfo = getServerDirectory(server, port, adminuser, password,
                                           "UPLOADS")
    sdRootFolder = os.path.join(uploadsFolderInfo['physicalPath'], 'admin')
    print '\nNOTE: Uploads\admin folder is: ' + sdRootFolder + '\n'
    if not os.path.exists(sdRootFolder):
        print '\nERROR: the uploads\\admin folder ' + sdRootFolder + ' does not exist. Exiting script.'
        sys.exit(exitErrCode)

    # Get collection of .sd files
    sdFiles = get_sd_files(sdRootFolder)

    # Get collection of ArcGIS Service services on server
    agsServices = get_ags_services(server, port, adminuser, password)

    # Get the portal properties for each portal item referenced by the service
    # according to the services' json info
    portal = Portal('https://' + server + ':7443/arcgis', adminuser, password)

    props = getPortalPropsForServices(portal, agsServices)

    # Get list of item ids for all specified users
    userItemIDs = None
    if users:
        userItemIDs = getItemsIDs(portal, users)

    # Determine which sd files to copy
    sdFilesToCopy = filesToCopy(sdFiles, agsServices, userItemIDs)

    # Copy sd files
    if doCopy:
        copySDFiles(sdFilesToCopy, targetFolder, agsServices, props)

    # Print report
    report(sdFilesToCopy, agsServices)

    print '\nDone.'
def main(argv=None):
    portal = Portal('http://portaldev.esri.com')
    template_name = 'Map Notes'
    file_gdb_path = 'C:/Temp/MapNotes.gdb'

    # Retrieve the layer definitions (schemas) for the specified
    # feature collection template
    template_id = portal.feature_collection_templates(q=template_name)[0]['id']
    template = portal.item_data(template_id, return_json=True)
    template_schemas = [layer['layerDefinition'] for layer in template['layers']]

    # Create the file GDB with feature classes for each schema
    create_file_gdb(file_gdb_path, template_schemas)

    # Get all webmaps, pull out features that match the template schemas, and
    # then load them into the corresponding feature classes in the file GDB
    for webmap in portal.webmaps():
        for template_schema in template_schemas:
            features = webmap.features([template_schema])
            if features:
                load_features(file_gdb_path, template_schema['name'], features)
Exemple #42
0
def invite_org_user():
    portal = Portal('http://wittakermathot.maps.arcgis.com', 'wmathot', '***')

    # Prepare the invitations
    invitations = [
            {'fullname': 'James Bond', 'username': '******',
             'email': '*****@*****.**', 'role': 'account_user'}]

    # Invite users. Log those who werent invited
    not_invited = portal.invite(invitations, 'test1', 'test2')
    if not_invited:
        print 'Not invited: ' + str(not_invited)

    # Accept the invitations and set the user's password to their username
    accepted_count = 0
    for invitation in invitations:
        username = invitation['username']
        for pending_invitation in portal.invitations(['id', 'username']):
            if username == pending_invitation['username']:
                invitation_id = pending_invitation['id']
                new_password = username
                is_reset = portal.reset_user(username, invitation_id, new_password)
                if is_reset:
                    portal_as_user = Portal('http://www.arcgis.com', username, new_password)
                    is_accepted = portal_as_user.accept(invitation_id)
                    if is_accepted:
                        accepted_count += 1

    print 'Invited ' + str(len(invitations)) + ', Accepted ' + str(accepted_count)
def share_templates(portaladdress, username, password):

    # Create portal connection
    portal = Portal(portaladdress, username, password)

    print '\nShare web app templates with "AFMI Web Application Templates" group...'
    results = share_default_webapp_templates(
        portal,
        portal.logged_in_user()['username'], 'AFMI Web Application Templates')
    if results['success']:
        print '\tDone.'
    else:
        print 'ERROR: {}'.format(results['message'])

    print '\nShare web app templates with "AFMI Gallery Templates" group...'
    results = share_default_gallery_templates(
        portal,
        portal.logged_in_user()['username'], 'AFMI Gallery Templates')
    if results['success']:
        print '\tDone.'
    else:
        print 'ERROR: {}'.format(results['message'])
Exemple #44
0
def create_demographics_group():
    arcgisonline = Portal('http://www.arcgis.com')
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    owner = portal.logged_in_user()['username']
    items = arcgisonline.search(q='demographics owner:esri ' + WEBMAP_ITEM_FILTER)
    copied_items = copy_items(items, arcgisonline, portal, owner)
    group_id = portal.create_group({'title': 'Demographics', 'access': 'public',
                                    'tags': 'demographics'},
                                   thumbnail='http://bit.ly/WEaIh5')
    for item_id in copied_items.values():
        portal.share_items(owner, [item_id], [group_id], True, True)
Exemple #45
0
def copy_users():
    source = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    owners = ['admin', 'wmathot']
    target_owner = target.logged_in_user()['username']
    for owner in owners:
        groups = source.groups(q='owner:' + owner)
        copied_groups = copy_groups(groups, source, target, target_owner)
        copied_items = copy_user_contents(source, owner, target, target_owner)
        for item_id in copied_items.keys():
            sharing = source.user_item(item_id)[1]
            if sharing['access'] != 'private':
                target_item_id = copied_items[item_id]
                target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                    if id in copied_groups]
                share_org = (sharing['access'] == 'org')
                share_public = (sharing['access'] == 'public')
                if not target.is_multitenant():
                    share_public = (share_public or share_org)
                target.share_items(target_owner, [target_item_id],
                                   target_group_ids,\
                                   share_org or share_public,\
                                   share_public)
def main(argv=None):
    portal = Portal('http://portaldev.esri.com')
    template_name = 'Map Notes'
    file_gdb_path = 'C:/Temp/MapNotes.gdb'

    # Retrieve the layer definitions (schemas) for the specified
    # feature collection template
    template_id = portal.feature_collection_templates(q=template_name)[0]['id']
    template = portal.item_data(template_id, return_json=True)
    template_schemas = [
        layer['layerDefinition'] for layer in template['layers']
    ]

    # Create the file GDB with feature classes for each schema
    create_file_gdb(file_gdb_path, template_schemas)

    # Get all webmaps, pull out features that match the template schemas, and
    # then load them into the corresponding feature classes in the file GDB
    for webmap in portal.webmaps():
        for template_schema in template_schemas:
            features = webmap.features([template_schema])
            if features:
                load_features(file_gdb_path, template_schema['name'], features)
Exemple #47
0
def set_home_page_banner():
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    portal.add_resource('custom-banner.jpg',\
                        data='http://www.myterradesic.com/images/header-globe.jpg')
    portal.update_property('rotatorPanels', \
        [{"id":"banner-custom", "innerHTML": "<img src='http://" + portal.hostname +\
        "/sharing/accounts/self/resources/custom-banner.jpg?token=SECURITY_TOKEN' " +\
        "style='-webkit-border-radius:0 0 10px 10px; -moz-border-radius:0 0 10px 10px; " +\
        "-o-border-radius:0 0 10px 10px; border-radius:0 0 10px 10px; margin-top:0; " +\
        "width:960px; height:180px;'/>"}])
Exemple #48
0
def calc_group_stats():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    items_min, items_mean, items_max, items_stdv = \
            portalpy.stats.group_item_stats(portal)
    print 'Item Count (Min): ' + str(items_min)
    print 'Item Count (Mean): ' + str(items_mean)
    print 'Item Count (Min): ' + str(items_max)
    print 'Item Count (StdDev): ' + str(items_stdv)

    members_min, members_mean, members_max, members_stdv = \
            portalpy.stats.group_member_stats(portal)
    print 'Member Count (Min): ' + str(members_min)
    print 'Member Count (Mean): ' + str(members_mean)
    print 'Member Count (Min): ' + str(members_max)
    print 'Member Count (StdDev): ' + str(members_stdv)
Exemple #49
0
def copy_users():
    source = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    owners = ['admin', 'wmathot']
    target_owner = target.logged_in_user()['username']
    for owner in owners:
        groups = source.groups(q='owner:' + owner)
        copied_groups = copy_groups(groups, source, target, target_owner)
        copied_items = copy_user_contents(source, owner, target, target_owner)
        for item_id in copied_items.keys():
            sharing = source.user_item(item_id)[1]
            if sharing['access'] != 'private':
                target_item_id = copied_items[item_id]
                target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                    if id in copied_groups]
                share_org = (sharing['access'] == 'org')
                share_public = (sharing['access'] == 'public')
                if not target.is_multitenant():
                    share_public = (share_public or share_org)
                target.share_items(target_owner, [target_item_id],
                                   target_group_ids,\
                                   share_org or share_public,\
                                   share_public)
Exemple #50
0
def update_hostname_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_map = {'wh94.fltplan.com:8080': 'wh94.fltplan.com'}
    url_items = portal.search(['id', 'type', 'url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        url = item.get('url')
        if url:
            url = normalize_url(url)
            host = parse_hostname(url, include_port=True)
            if host in hostname_map:
                url = url.replace(host, hostname_map[host])
                portal.update_item(item['id'], {'url': url})
    webmaps = portal.webmaps()
    for webmap in webmaps:
        is_update = False
        for url in webmap.urls():
            normalized_url = normalize_url(url)
            host = parse_hostname(normalized_url, include_port=True)
            if host in hostname_map:
                new_url = normalized_url.replace(host, hostname_map[host])
                webmap.data = webmap.data.replace(url, new_url)
                is_update = True
        if is_update:
            portal.update_webmap(webmap)
Exemple #51
0
def update_hostname_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_map = {'wh94.fltplan.com:8080': 'wh94.fltplan.com'}
    url_items = portal.search(['id','type','url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        url = item.get('url')
        if url:
            url = normalize_url(url)
            host = parse_hostname(url, include_port=True)
            if host in hostname_map:
                url = url.replace(host, hostname_map[host])
                portal.update_item(item['id'], {'url': url})
    webmaps = portal.webmaps()
    for webmap in webmaps:
        is_update = False
        for url in webmap.urls():
            normalized_url = normalize_url(url)
            host = parse_hostname(normalized_url, include_port=True)
            if host in hostname_map:
                new_url = normalized_url.replace(host, hostname_map[host])
                webmap.data = webmap.data.replace(url, new_url)
                is_update = True
        if is_update:
            portal.update_webmap(webmap)
Exemple #52
0
def proxy_through_fiddler():
    portal = Portal('http://www.arcgis.com', proxy_host='localhost', proxy_port=8888)
    print portal.info()
Exemple #53
0
def most_active_publishers():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    results = portal.search(['owner','count(owner)'], group_fields=['owner'], scope='org')
    pprint(results, indent=2)
Exemple #54
0
def most_reviewed_publishers():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    results = portal.search(['owner','sum(numComments)'], group_fields=['owner'])
    pprint(results, indent=2)
def main():
    
    totalSuccess = True
    out_file = None
    
    # Check arguments
    results = check_args()
    if not results:
        sys.exit(exitErrCode)
    
    # Get parameter values
    portal_url, user, password, output_file, output_per_user = results
    
    try:
        access_mode = 'w'
        
        # Create portal object
        portal = Portal(portal_url, user, password)
        
        if not portal:
            raise Exception('ERROR: Could not create "portal" object.')
        
        if not portal.logged_in_user():
            raise Exception('\nERROR: Could not sign in with specified credentials.')
        
        # Get portal users
        portal_users = portal.org_users()
        
        out_file = open(output_file, access_mode)
        out_file_dir = os.path.dirname(output_file)
        
        for portal_user in portal_users:
            
            user_name = portal_user['username']
            
            if user_name in username_exclude:
                continue
            
            if output_per_user:
                service_list_outfile = os.path.join(out_file_dir, '{}_ServiceList.txt'.format(user_name))
                service_list_qc_outfile = os.path.join(out_file_dir, '{}_CreateServiceList_output.txt'.format(user_name))
                access_mode = 'OVERWRITE'
                redirect = '>'
            else:
                service_list_outfile = os.path.join(out_file_dir, 'ServiceList.txt')
                service_list_qc_outfile = os.path.join(out_file_dir, 'CreateServiceList_output.txt')
                access_mode = 'APPEND'
                redirect = '>>'
                
            script_parameters = '{} {} {} {} {} {} {} {} {}'.format(
                    os.path.join(script_path, 'CreateServiceList.py'),
                    portal_url, user, password, service_list_outfile,
                    access_mode, user_name, redirect, service_list_qc_outfile)
            
            out_file.write(script_parameters + '\n')
        
        print '\nCreated output batch file: {}\n'.format(output_file)
        print 'Done.'
        
    except:
        totalSuccess = False
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
     
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        if hasattr(out_file, 'close'):
            out_file.close()
        if totalSuccess:
            sys.exit(0)
        else:
            sys.exit(1)
def main():
    exit_err_code = 1
    
    # Print/get script arguments
    results = print_args()
    if not results:
        sys.exit(exit_err_code)
    portal_address, adminuser, password, delete_option = results
    
    total_success = True
    title_break_count = 150
    section_break_count = 100
    
    print '=' * title_break_count
    print 'Find Hosted Services'
    print '=' * title_break_count
    
    try:
        file_name = 'hosted_service_item_mapping.json'
        if os.path.exists(file_name):
            os.remove(file_name)
                
        portal = Portal(portal_address, adminuser, password)
        
        print '\n{}'.format('-' * section_break_count)
        print '- Searching for hosted service items...'
        hosted_service_items = get_hosted_service_items(portal)
        
        print '- Found {} hosted service items:'.format(len(hosted_service_items))
        for hosted_service_item in hosted_service_items:
            print format_item_info(hosted_service_item)
        
        print '\n{}'.format('-' * section_break_count)
        print '- Searching for orphaned hosted service items...'
        o_hosted_service_items = get_orphaned_hosted_service_items(portal)
        
        print '- Found {} orphaned hosted service items:'.format(len(o_hosted_service_items))
        for o_hosted_service_item in o_hosted_service_items:
            print format_item_info(o_hosted_service_item)
        
        print '\n{}'.format('-' * section_break_count)
        print '- Map orphaned hosted service item to hosted service item...'
        item_mapping = create_search_replace_id_map(portal)
        if len(item_mapping) == 0:
            print 'No orphaned service items to map.'
            
        if len(item_mapping) > 0:
            for hosted_service_item in hosted_service_items:
                orphanedID = 'NOT FOUND'
                for id_map in item_mapping:
                    if hosted_service_item['id'] == id_map[replace_key]:
                        orphanedID = id_map[search_key]
                print format_item_info(hosted_service_item) + \
                                ' ***[OrphanedID: {}]'.format(orphanedID)
            
            print '\nNOTE: item mapping info written to file "{}" in directory: {}'.format(file_name, os.getcwd())
            json.dump(item_mapping, open(file_name,'w'))
        
        if len(o_hosted_service_items) > 0 and delete_option:
            print '\n{}'.format('-' * section_break_count)
            print '- You selected to delete orphaned hosted service items.'
            print '  Will delete the following items...'
            
            for o_hosted_service_item in o_hosted_service_items:
                print format_item_info(o_hosted_service_item)
        
            user_response = raw_input("\nDo you want to continue with the delete? Enter 'y' to continue: ")
    
            if validate_user_repsonse_yesno(user_response):
                for o_hosted_service_item in o_hosted_service_items:
                    print 'Deleting...'
                    print '\t{}'.format(format_item_info(o_hosted_service_item))
                    resp = portal.delete_item(o_hosted_service_item['id'])
                    print resp
                
    except:
        total_success = False
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error 
        # into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + \
                "\nError Info:\n" + str(sys.exc_info()[1])
        
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        print '\nDone.'
        if total_success:
            sys.exit(0)
        else:
            sys.exit(exit_err_code)
Exemple #57
0
def portal_info_plus():
    portal = Portal('http://portaldev.esri.com')
    print portal.info()
    pprint(portal.properties())
    pprint(portal.languages())
    pprint(portal.regions())
    pprint(portal.basemaps(['title']))
    pprint(portal.color_sets(['title']))
    pprint(portal.featured_items(['title']))
    pprint(portal.featured_items_homepage(['title']))
    pprint(portal.feature_collection_templates(['title']))
    pprint(portal.symbol_sets(['title']))
    pprint(portal.gallery_templates(['title']))
    pprint(portal.webmap_templates(['title']))
Exemple #58
0
def portal_info():
    portal = Portal('http://portaldev.esri.com')
    print portal.info()
Exemple #59
0
def most_active_publishers():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    results = portal.search(['owner', 'count(owner)'],
                            group_fields=['owner'],
                            scope='org')
    pprint(results, indent=2)
Exemple #60
0
def portal_info_plus():
    portal = Portal('http://portaldev.esri.com')
    print portal.info()
    pprint(portal.properties())
    pprint(portal.languages())
    pprint(portal.regions())
    pprint(portal.basemaps(['title']))
    pprint(portal.color_sets(['title']))
    pprint(portal.featured_items(['title']))
    pprint(portal.featured_items_homepage(['title']))
    pprint(portal.feature_collection_templates(['title']))
    pprint(portal.symbol_sets(['title']))
    pprint(portal.gallery_templates(['title']))
    pprint(portal.webmap_templates(['title']))