Copy AGO Notebook Files In ArcGIS Pro Notebook

532
3
12-08-2022 07:09 AM
ChristopherMask
New Contributor III

Would like to know if it is possible to copy the zip files created and stored in the /arcgis/home directory of AGO Notebook to a local directiory using ArcGIS Pro Notebook. The procedures are as followed:

 

Input 1

from arcgis.gis import GIS
import datetime as dt
gis = GIS('home')

 

Input 2 ? (Connect and query content in the AGO notebook directory /arcgis/home and loop through to get items [])

 

Input 3 ? (Download items [] to folder (ie. C:\Backups)

 

 

 

Tags (2)
0 Kudos
3 Replies
DanielMiranda2
Occasional Contributor

This can be helpful for explaining how to search for content: Accessing and creating content | ArcGIS API for Python.

When you say the "AGO notebook directory" do you mean all of your own notebooks? If so, we can search for notebooks by your username. Then, download them to a specified folder, using the original titles:

(replace username with your ArcGIS Online username):

search_notebooks = gis.content.search(query='owner:username type:notebook')

for notebook in search_notebooks:
    notebook.download(r'C:\ArcGIS', f'{notebook.title}.ipynb')

 

You can adjust the search query as needed to get the notebooks you want. Note that this will just download each notebook as a .ipynb file, which you can then open in ArcGIS Pro.

0 Kudos
ChristopherMask
New Contributor III

Thanks for the response. The above code works, but I am attempting to get the files. (See Image)

The idea is to create a task to run an AGO notebook for each day, which backups the organizational feature layers. The code creates a zipfile for each feature layer and downloads to the /arcgis/home directory. (This part is completed).  

The second objective is to copy the zipfiles from the directory /arcgis/home to a local directory (C:\). I want to accomplish this by in ArcGIS Pro notebook, if possible.

Thoughts?

0 Kudos
ChristopherMask
New Contributor III

I attempted to use this python code, but getting Permission denied 

get_url=urllib.request.urlretrieve("https://OKForestry.maps.arcgis.com/home","CopyZipFilesFromAGO.zip")

 

0 Kudos