Skip to content

Instantly share code, notes, and snippets.

@rvg296
Last active July 22, 2020 15:26
Show Gist options
  • Save rvg296/9cd450f60dbb423e9e55efc69009f1f3 to your computer and use it in GitHub Desktop.
Save rvg296/9cd450f60dbb423e9e55efc69009f1f3 to your computer and use it in GitHub Desktop.
A short script for exporting feature service data from ArcGIS Online, download it and then delete the item.
'''This script can be only be run either by Organization Administrator or the Feature Service Owner for exporting the data'''
import time
from datetime import date
import urllib, zipfile,json
from arcgis.gis import GIS
# Feature Service Item ID
featureService_ID = "***************"
# Local folder where the data will be downloaded (include slash at the end)
download_folder = r"D:/"
# ArcGIS user credentials to authenicate against the portal
credentials = { 'userName' : '*******', 'passWord' : '*******'}
# Address of your ArcGIS portal
portal_url = r"https://www.arcgis.com/"
#You can authenticate with Pro or ArcGIS Online
#gis = GIS("pro")
#Authenticate against portal
gis = GIS(portal_url,credentials['userName'], credentials['passWord'])
item = gis.content.get(featureService_ID)
title = Report+date.today().strftime('%m-%Y-%d')
#Can be any format for exporting
exportedData = item.export(title,export_format="CSV")
print("Exported Successfully")
#Download into your desired folder.
exportedData.download(download_folder)
print("Downloaded successfully")
#Delete the exported data, if you dont need it in AGOL
exportedData.delete()
print("Deleted in AGOL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment