def updateItemUrl(self, itemId, oldUrl, newUrl, folderID=None):
        '''
        Use this to update the URL for items such as Map Services.
        The oldUrl parameter is required as a check to ensure you are not
        accidentally changing the wrong item or url.
        This can also replace part of a URL. The text of oldUrl is replaced with the text of newUrl. For example you could change just the host name of your URLs.
        '''
        try:
            params = urllib.urlencode({'token' : self.user.token,
                                       'f' : 'json'})
            print 'Getting Info for: ' + itemId
            # Get the item data
            reqUrl = self.user.portalUrl + '/sharing/rest/content/items/' + itemId + '?' + params
            itemReq = urllib.urlopen(reqUrl).read()
            itemString = str(itemReq)
            itemInfo = json.loads(itemString)

            if not itemInfo.has_key('url'):
                print itemInfo['title'] + ' doesn\'t have a url property'
                return
            print 'Updating ' + itemInfo['title']
            existingURL = itemInfo['url']

            # Double check that the existing URL matches the provided URL
            if itemString.find(oldUrl) > -1:
                # Get the item folder.
                if itemInfo['ownerFolder']:
                    folderID = itemInfo['ownerFolder']
                else:
                    folderID = ''
                # Update the item URL
                updatedURL = existingURL.replace(oldUrl, newUrl)
                updateParams = urllib.urlencode({'url' : updatedURL})
                updateUrl = self.user.portalUrl + '/sharing/rest/content/users/' + self.user.username + '/' + folderID + '/items/' + itemId + '/update?' + params
                updateReq = urllib.urlopen(updateUrl, updateParams).read()
                modResponse = json.loads(updateReq)
                if modResponse.has_key('success'):
                    print "Successfully updated the url."
                else:
                    raise AGOPostError(itemId, modResponse['error']['message'])
            else:
                print 'Didn\'t find the specified old URL: ' + oldUrl
        except __HOLE__ as e:
            print e
        except AGOPostError as e:
            print 'Error updating item: ' + e.msg
dataset/ETHPy150Open Esri/ago-tools/agoTools/utilities.py/Utilities.updateItemUrl