I would like to have an automated process which does the following:
Is this solution possible with ArcREST?
I will post my code sample when I return to my desk.
I have used a piece of your code Kevin in addition to the addItem method from ArcREST. My item adds, and my token and item ID print, however, when I try to pass the itemID to the function below it does not publish and no errors are returned.
import arcrestimport jsonimport requestsimport urllibimport urllib2if __name__ == "__main__": username = "myusername" password = "mypassword" portalId = "myportalnumber" url = "http://myorg.maps.arcgis.com/" thumbnail_url = '' file = "myflie.csv" securityHandler = arcrest.AGOLTokenSecurityHandler(username, password) # Create the administration connection # admin = arcrest.manageorg.Administration(url, securityHandler) # Connect to the portal # portal = admin.portals(portalId) # Access the content properties to add the item # content = admin.content # Provide the item parameters # itemParams = arcrest.manageorg.ItemParameter() itemParams.thumbnailurl = thumbnail_url itemParams.title = "CSVTest" itemParams.type = "CSV" itemParams.tags = "test" # Enter in the username you wish to load the item to # usercontent = content.usercontent(username=username) # print usercontent.addItem(filePath=file, # itemParameters=itemParams, overwrite=True) agolID= usercontent.addItem(itemParameters=itemParams)['id'] print agolID itemId = agolID tags = "Demo, Publishing" securityHandler = arcrest.AGOLTokenSecurityHandler(username, password)### Generate Token ###gtUrl = 'https://www.arcgis.com/sharing/rest/generateToken'gtValues = {'username' : 'myuser','password' : 'mypass','referer' : 'http://www.arcgis.com','f' : 'json' }gtData = urllib.urlencode(gtValues)gtRequest = urllib2.Request(gtUrl, gtData)gtResponse = urllib2.urlopen(gtRequest)gtJson = json.load(gtResponse)token = gtJson['token']print tokendef PublishService(Short, agolID, username, token, itemName, publishParams, XField, YField): ''' Publishes the input itemID (uploaded CSV) this is using a post request from urllib, the JSON input can be generated by the analyze function. Item name, X and Y fields are specified''' publishURL = 'http://myOrg.maps.arcgis.com/sharing/rest/content/users/myUser/publish'.format(Short, username) publishParams['CSVTest'] = itemName publishParams['locationType'] = 'coordinates' publishParams['Y_COR'] = YField publishParams['X_COR'] = XField query_dict = { 'itemID': agolID, 'filetype': 'csv', 'f': 'json', 'token': token, 'publishParameters'
ublishParams} query_dict['publishParameters'] = json.dumps(query_dict['publishParameters'], sort_keys=False) request = requests.post(publishURL, data=query_dict) print request.json()`
أكثر...
- Adds a CSV to our portaL/AGOL organization account.
- Publishes the item as a hosted feature service.
- Consumes hosted feature back unto EGIS environment.
Is this solution possible with ArcREST?
I will post my code sample when I return to my desk.
I have used a piece of your code Kevin in addition to the addItem method from ArcREST. My item adds, and my token and item ID print, however, when I try to pass the itemID to the function below it does not publish and no errors are returned.
import arcrestimport jsonimport requestsimport urllibimport urllib2if __name__ == "__main__": username = "myusername" password = "mypassword" portalId = "myportalnumber" url = "http://myorg.maps.arcgis.com/" thumbnail_url = '' file = "myflie.csv" securityHandler = arcrest.AGOLTokenSecurityHandler(username, password) # Create the administration connection # admin = arcrest.manageorg.Administration(url, securityHandler) # Connect to the portal # portal = admin.portals(portalId) # Access the content properties to add the item # content = admin.content # Provide the item parameters # itemParams = arcrest.manageorg.ItemParameter() itemParams.thumbnailurl = thumbnail_url itemParams.title = "CSVTest" itemParams.type = "CSV" itemParams.tags = "test" # Enter in the username you wish to load the item to # usercontent = content.usercontent(username=username) # print usercontent.addItem(filePath=file, # itemParameters=itemParams, overwrite=True) agolID= usercontent.addItem(itemParameters=itemParams)['id'] print agolID itemId = agolID tags = "Demo, Publishing" securityHandler = arcrest.AGOLTokenSecurityHandler(username, password)### Generate Token ###gtUrl = 'https://www.arcgis.com/sharing/rest/generateToken'gtValues = {'username' : 'myuser','password' : 'mypass','referer' : 'http://www.arcgis.com','f' : 'json' }gtData = urllib.urlencode(gtValues)gtRequest = urllib2.Request(gtUrl, gtData)gtResponse = urllib2.urlopen(gtRequest)gtJson = json.load(gtResponse)token = gtJson['token']print tokendef PublishService(Short, agolID, username, token, itemName, publishParams, XField, YField): ''' Publishes the input itemID (uploaded CSV) this is using a post request from urllib, the JSON input can be generated by the analyze function. Item name, X and Y fields are specified''' publishURL = 'http://myOrg.maps.arcgis.com/sharing/rest/content/users/myUser/publish'.format(Short, username) publishParams['CSVTest'] = itemName publishParams['locationType'] = 'coordinates' publishParams['Y_COR'] = YField publishParams['X_COR'] = XField query_dict = { 'itemID': agolID, 'filetype': 'csv', 'f': 'json', 'token': token, 'publishParameters'
أكثر...