AnsweredAssumed Answered

Can someone help me fix this Automated Download script?

Question asked by dinubaAGOLAdmin on Jul 20, 2020
Latest reply on Jul 20, 2020 by jskinner-esristaff

from arcgis.gis import GIS
#from datetime import datetime

 

#Python Standard Library modules
from pathlib import Path
from zipfile import ZipFile


print('import complete')
#store the IF of the public data item being downloaded
data_item_id = 'a3e1fb26f38d487480299b570994ffce'

 

#login to ArcGIS Online
#user = 
#password = '
gis = GIS(username='x, password='!x')

print('Login successful')

#use API to retrieve and item object data_item
data_item = gis.content.get(data_item_id)

#if no Item with that Id, return None
data_item

 

#download zipfile to the server's current location r'G:\Dinuba\2020\ArcGISOnline\Fire_hydrant_CSVs'
data_path = Path(r'G:\Dinuba\2020\ArcGISOnline\Fire_hydrant_CSVs')

 

#timestamp = time.strftime('%Y%m%d')
zip_path = data_path.joinpath('hydrant.zip')
extract_path = data_path.joinpath('FireHydrants')
data_item.download(save_path=data_path)


#extract zipfile, make list of contents in directory
zip_file = ZipFile(zip_path)
zip_file.extractall(path=extract_path)
list(file.name for file in extract_path.glob('*'))
print('Download Complete')

 

This is the error I keep getting.  I don't understand what I am doing wrong. 

Traceback (most recent call last):
  File "C:/Users/brossi/Desktop/download_data.py", line 34, in <module>
    zip_file = ZipFile(zip_path)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\zipfile.py", line 1113, in __init__
    self.fp = io.open(file, filemode)
FileNotFoundError: [Errno 2] No such file or directory: 'G:\\Dinuba\x820\\ArcGISOnline\\Fire_hydrant_CSVs\\hydrant20200720'
>>>
I disabled the timestamp because I just wanted to get the script working but for some reason no matter what I do it keeps coming up with  this. 

Outcomes