I am trying to somehow backup WebMaps from AGOL and am thinking the ConvertWebMapToMapDocument function could be helpful with this. I thought of saving (1) the json file itself and (2) save it as mxd. While I think saving the json file itself shouldn't be that dificult, I'm struggeling finding a way to make ConvertWebMapToMapDocument work.
Unfortunately, when looking through different examples in the documentation and through the web, I always find a WebMap_as_JSON variable (or similar named) that gets its value from a tool as it seems (getAttributeAsText(0)). I assume that it expects the json code of the WebMap which could be this one http://www.arcgis.com/sharing/rest/content/items/95562b6a24994641bbbaa3d1f2b7cf4f/data?f=pjson.
I managed to read the content by adding
jsonResponse <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>webmap<SPAN class="punctuation token">)</SPAN>
WebMap_as_JSON <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>jsonResponse<SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
When I print now WebMap_as_JSON I get the same content as at the URL above though in a different order.
But when I try to convert now my WebMap_as_JSON to a mapdocument with
result <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ConvertWebMapToMapDocument<SPAN class="punctuation token">(</SPAN>WebMap_as_JSON<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
I receive a Runtime Error:
RuntimeError: Expected to find comma, colon or start of array; state : startOfObject; buffer : {u'authoringAppVersion': u'5.1', u'authoringApp':
So I assume it's still not the right content as the input.
I would highly appreciate if someone could give me a hint how to get the right input for ConvertWebMapToMapDocument. Thanks a lot!
For you to try, this is what I have so far:
<SPAN class="keyword token">import</SPAN> arcrest
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> urllib<SPAN class="punctuation token">,</SPAN> urllib2<SPAN class="punctuation token">,</SPAN> json
webmap<SPAN class="operator token">=</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2Fcontent%2Fitems%2F95562b6a24994641bbbaa3d1f2b7cf4f%2Fdata%3Ff%3Dpjson" target="_blank">http://www.arcgis.com/sharing/rest/content/items/95562b6a24994641bbbaa3d1f2b7cf4f/data?f=pjson</A><SPAN>"</SPAN></SPAN>
jsonResponse <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>webmap<SPAN class="punctuation token">)</SPAN>
WebMap_as_JSON <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>jsonResponse<SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>WebMap_as_JSON<SPAN class="punctuation token">)</SPAN>
result <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ConvertWebMapToMapDocument<SPAN class="punctuation token">(</SPAN>WebMap_as_JSON<SPAN class="punctuation token">)</SPAN>
mxd <SPAN class="operator token">=</SPAN> result<SPAN class="punctuation token">.</SPAN>mapDocument
mxd<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"<here is my path to the output mxd file>"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Map document saved"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>