Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

additem_webmap_sample.py fails on print user.addItem #170

Closed tpcolson closed 8 years ago

tpcolson commented 8 years ago

I'm sure this is a silly syntax error:

When I copy https://github.com/Esri/ArcREST/blob/master/samples/additem_webmap_sample.py exactly, and only change to my AGOL UID and PW, it fails on syntax at print user.addItem. I've tried numerous combinations of including, not including portalId (which I assume from http://esri.github.io/ArcREST/arcrest.manageorg.administration.html to be the AGOL Org ID), and just for giggle, didn't even include a PW, and still "There's an error in your program: invalid syntax" and user is high lighted 3rd from last line.

I am able to successfully run other ArcREST samples. Py 2.7.8

tpcolson commented 8 years ago

Resolved by the following modification to the sample: Additional paranthesesis around "print" and defined map_jason correctly:

from __future__ import print_function
import arcrest
import json
if __name__ == "__main__":
    username = ""
    password = ""
    portalId = ""
    url = "http://www.arcgis.com/"
    thumbnail_url = "http://its.ucsc.edu/software/images/arcgis.jpg"
    map_json = {
    "operationalLayers":[
        {"id":"a",
         "type":"CSV",
         "layerType":"CSV",
         "title":"eqs",
         "visibility":True,
         "opacity":1,
         "url":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_hour.csv",
         "layerDefinition":{"drawingInfo":{"renderer":{"description":"",
                                                       "symbol":{
                                                           "style":"esriSMSCircle",
                                                           "angle":0,
                                                           "color":[255,0,0,0],
                                                           "yoffset":0,
                                                           "type":"esriSMS",
                                                           "xoffset":0,
                                                           "size":8
                                                           },
                                                       "rotationExpression":"",
                                                       "label":"test",
                                                       "rotationType":"geographic",
                                                       "type":"simple"},
                                           "fixedSymbols":False},
                            "name":"csv",
                            "hasAttachments":False,
                            "definitionExpression":"",
                            "maxScale":0,
                            "objectIdField":"__OBJECTID",
                            "minScale":0,
                            "type":"Feature Layer",
                            "extent":""},
         "locationInfo":{
             "locationType":"coordinates",
             "latitudeFieldName":"latitude",
             "longitudeFieldName":"longitude"
             },
         "columnDelimiter":","},
        {"id":"csv_8583",
         "type":"CSV",
         "layerType":"CSV",
         "title":"all_hour",
         "visibility":True,
         "opacity":1,
         "url":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.csv",
         "layerDefinition":{
             "geometryType":"esriGeometryPoint",
             "objectIdField":"__OBJECTID",
             "type":"Feature Layer",
             "typeIdField":"",
             "drawingInfo":{
                 "renderer":{
                     "type":"simple",
                     "symbol":{
                         "type":"esriPMS",
                         "url":"http://static.arcgis.com/images/Symbols/Basic/RedSphere.png",
                         "imageData":"iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQBQYWludC5ORVQgdjMuNS4xTuc4+QAAB3VJREFUeF7tmPlTlEcexnve94U5mANQbgQSbgiHXHINlxpRIBpRI6wHorLERUmIisKCQWM8cqigESVQS1Kx1piNi4mW2YpbcZONrilE140RCTcy3DDAcL/zbJP8CYPDL+9Ufau7uqb7eZ7P+/a8PS8hwkcgIBAQCAgEBAICAYGAQEAgIBAQCAgEBAICAYGAQEAgIBAQCDx/AoowKXFMUhD3lQrioZaQRVRS+fxl51eBTZUTdZ41U1Rox13/0JF9csGJ05Qv4jSz/YPWohtvLmSKN5iTGGqTm1+rc6weICOBRbZs1UVnrv87T1PUeovxyNsUP9P6n5cpHtCxu24cbrmwKLdj+osWiqrVKhI0xzbmZ7m1SpJ+1pFpvE2DPvGTomOxAoNLLKGLscZYvB10cbYYjrJCb7A5mrxleOBqim+cWJRakZY0JfnD/LieI9V1MrKtwokbrAtU4Vm0A3TJnphJD4B+RxD0u0LA7w7FTE4oprOCMbklEGNrfdGf4IqnQTb4wc0MFTYibZqM7JgjO8ZdJkpMln/sKu16pHZGb7IfptIWg389DPp9kcChWODoMuDdBOhL1JgpisbUvghM7AqFbtNiaFP80RLnhb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IGKgO0OrlIaebU/HYOQDNbQnojB4NJyGD0NPfjA0bwTRE6Q7hsUcWhkWN8yZqSQlWWGECAZLmJfJmbrvVSI8taK37xpbdB/wQW8xPee/8xIGjvlj8IQ/hk4G0JbWcX8MHPVDX4kveoq8ocn3xLM33NCZRcPHOGJYZIKfpQyq7JjHS6yJjcHujLHADgkpuC7h8F8zEVqXSNC2awE69lqhs8AamkO26HrbDt2H7dBVQov2NcW26CiwQtu+BWjdY4n2nZboTbfCmKcCnRyDO/YmyLPnDlHvjDH8G6zhS9/wlEnYR7X00fWrFYuWdVI0ZpuhcbcczW/R2qdAcz6t/bRov4mONeaaoYl+p22rHF0bVNAmKtBvweIXGxNcfFH8eNlC4m6wMWMusEnKpn5hyo48pj9gLe4SNG9QoGGLAk8z5XiaJUd99u8122/IpBA2K9BGg2vWWKAvRYVeLzEa7E1R422m2+MsSTem97nSYnfKyN6/mzATv7AUgqcMrUnmaFlLX3ysM0fj+t/b5lQLtK22QEfyAmiSLKFZpUJ7kBRPXKW4HqCYynWVHKSG2LkyZex1uO1mZM9lKem9Tx9jjY5iNEYo0bKMhn7ZAu0r6H5PpLXCAq0rKJClSjSGynE/QIkrQYqBPe6S2X+AJsY2Ped6iWZk6RlL0c2r5szofRsO9R5S1IfQLRCpQL1aifoYFerpsbkuTImaUJXuXIDiH6/Ys8vm3Mg8L2i20YqsO7fItKLcSXyn0kXccclVqv3MS6at9JU/Ox+ouns+SF6Z4cSupz7l8+z1ucs7LF1AQjOdxfGZzmx8Iu1TRcfnrioICAQEAgIBgYBAQCAgEBAICAQEAgIBgYBAQCAgEBAICAQEAv8H44b/6ZiGvGAAAAAASUVORK5CYII=",
                         "contentType":"image/png",
                         "width":15,"height":15}},
                 "fixedSymbols":True},
             "fields":[{
                 "name":"__OBJECTID",
                 "alias":"__OBJECTID",
                 "type":"esriFieldTypeOID",
                 "editable":False,
                 "Noneable":False,
                 "domain":None},
                       {"name":"time","alias":"time","type":"esriFieldTypeDate","length":36,"editable":True,"Noneable":True,"domain":None},{"name":"latitude","alias":"latitude","type":"esriFieldTypeDouble","editable":True,"Noneable":True,"domain":None},{"name":"longitude","alias":"longitude","type":"esriFieldTypeDouble","editable":True,"Noneable":True,"domain":None},{"name":"depth","alias":"depth","type":"esriFieldTypeDouble","editable":True,"Noneable":True,"domain":None},{"name":"mag","alias":"mag","type":"esriFieldTypeDouble","editable":True,"Noneable":True,"domain":None},{"name":"magType","alias":"magType","type":"esriFieldTypeString","length":255,"editable":True,"Noneable":True,"domain":None},{"name":"nst","alias":"nst","type":"esriFieldTypeInteger","editable":True,"Noneable":True,"domain":None},{"name":"gap","alias":"gap","type":"esriFieldTypeInteger","editable":True,"Noneable":True,"domain":None},{"name":"dmin","alias":"dmin","type":"esriFieldTypeDouble","editable":True,"Noneable":True,"domain":None},{"name":"rms","alias":"rms","type":"esriFieldTypeDouble","editable":True,"Noneable":True,"domain":None},{"name":"net","alias":"net","type":"esriFieldTypeString","length":255,"editable":True,"Noneable":True,"domain":None},{"name":"id","alias":"id","type":"esriFieldTypeString","length":255,"editable":True,"Noneable":True,"domain":None},{"name":"updated","alias":"updated","type":"esriFieldTypeDate","length":36,"editable":True,"Noneable":True,"domain":None},{"name":"place","alias":"place","type":"esriFieldTypeString","length":255,"editable":True,"Noneable":True,"domain":None},{"name":"type","alias":"type","type":"esriFieldTypeString","length":255,"editable":True,"Noneable":True,"domain":None}],"types":[],"capabilities":"Query","name":"csv","extent":{"type":"extent","xmin":-16209420.29764264,"ymin":3785953.3038973636,"xmax":-10823505.034137173,"ymax":8414179.048043747,"spatialReference":{"wkid":102100}}},"popupInfo":{"title":"","fieldInfos":[{"fieldName":"__OBJECTID","label":"__OBJECTID","isEditable":False,"tooltip":"","visible":False,"format":None,"stringFieldOption":"textbox"},{"fieldName":"time","label":"time","isEditable":True,"tooltip":"","visible":True,"format":{"dateFormat":"longMonthDayYear"},"stringFieldOption":"textbox"},{"fieldName":"latitude","label":"latitude","isEditable":True,"tooltip":"","visible":True,"format":{"places":2,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"longitude","label":"longitude","isEditable":True,"tooltip":"","visible":True,"format":{"places":2,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"depth","label":"depth","isEditable":True,"tooltip":"","visible":True,"format":{"places":2,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"mag","label":"mag","isEditable":True,"tooltip":"","visible":True,"format":{"places":2,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"magType","label":"magType","isEditable":True,"tooltip":"","visible":True,"format":None,"stringFieldOption":"textbox"},{"fieldName":"nst","label":"nst","isEditable":True,"tooltip":"","visible":True,"format":{"places":0,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"gap","label":"gap","isEditable":True,"tooltip":"","visible":True,"format":{"places":0,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"dmin","label":"dmin","isEditable":True,"tooltip":"","visible":True,"format":{"places":2,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"rms","label":"rms","isEditable":True,"tooltip":"","visible":True,"format":{"places":2,"digitSeparator":True},"stringFieldOption":"textbox"},{"fieldName":"net","label":"net","isEditable":True,"tooltip":"","visible":True,"format":None,"stringFieldOption":"textbox"},{"fieldName":"id","label":"id","isEditable":True,"tooltip":"","visible":True,"format":None,"stringFieldOption":"textbox"},{"fieldName":"updated","label":"updated","isEditable":True,"tooltip":"","visible":True,"format":{"dateFormat":"longMonthDayYear"},"stringFieldOption":"textbox"},{"fieldName":"place","label":"place","isEditable":True,"tooltip":"","visible":True,"format":None,"stringFieldOption":"textbox"},{"fieldName":"type","label":"type","isEditable":True,"tooltip":"","visible":True,"format":None,"stringFieldOption":"textbox"}],"description":None,"showAttachments":False,"mediaInfos":[]},"locationInfo":{"locationType":"coordinates","latitudeFieldName":"latitude","longitudeFieldName":"longitude"},"columnDelimiter":","}],"baseMap":{"baseMapLayers":[{"id":"defaultBasemap","layerType":"ArcGISTiledMapServiceLayer","opacity":1,"visibility":True,
"url":"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"}],
"title":"Topographic"},
    "spatialReference":{"wkid":102100,"latestWkid":3857},"version":"2.0"}
    securityHandler = arcrest.AGOLTokenSecurityHandler(username,
                                                       password)
    #   Create the administration connection
    #
    admin = arcrest.manageorg.Administration(url, securityHandler)
    #   Access the content properties to add the item
    #
    content = admin.content
    #   Get the user    #
    user = content.users.user()
    #   Provide the item parameters
    #
    itemParams = arcrest.manageorg.ItemParameter()
    itemParams.title = "MY FIRST WEB MAP"
    itemParams.thumbnailurl = "http://its.ucsc.edu/software/images/arcgis.jpg"
    itemParams.type = "Web Map"
    itemParams.tags = "Map, Earthquake"
    itemParams.extent = "-180,-80.1787,180, 80.1787"

    #   Add the Web Map
    #
    print (user.addItem(itemParameters=itemParams,
                              overwrite=True,
                              text=json.dumps(map_json)))