def update_item_data(portal, item, hostname_map, id_map):
    '''Replace host name/item ids in item data'''

    if item['type'] in TEXT_BASED_ITEM_TYPES:
        
        try:
            itemdata = portal.item_data(item['id'])
        except Exception as err:
            print('ERROR: Exception: update_item_data function could not get item data for item: "{}"'.format(str(item.get('title'))))
            itemdata = None
        
        if itemdata:
            
            is_updated = False
            
            for host in hostname_map:
                search_str_list = [host, host.lower(), host.upper()]
                for search_str in search_str_list:
                    if itemdata.find(search_str) > -1:
                        itemdata = itemdata.replace(search_str, hostname_map[host])
                        is_updated = True

            for item_id in id_map:
                search_str_list = [item_id, item_id.lower(), item_id.upper()]
                for search_str in search_str_list:
                    if itemdata.find(search_str) > -1:
                        itemdata = itemdata.replace(search_str, id_map[item_id]["id"])
                        is_updated = True
            
            if is_updated:
                portal.update_item(item['id'], {'text': itemdata})     

    if item['type'] == 'CSV':
        update_csv_item(portal, item, hostname_map)
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/PortalContentPost.py/update_item_data/original