Skip to content

Instantly share code, notes, and snippets.

@dersteppenwolf
Last active January 18, 2016 22:03
Show Gist options
  • Save dersteppenwolf/404ff18218b0078a695d to your computer and use it in GitHub Desktop.
Save dersteppenwolf/404ff18218b0078a695d to your computer and use it in GitHub Desktop.
Export data from Arcgis Desktop to CartoDB using Python / Arcpy
# -*- coding: utf-8 -*-
# Requires CartoDB Toolbox for Arcgis http://gkudos.com/blog/2015/05/15/cartodb-toolbox/
# http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent
# python -m pip install requests[security]
# Import arcpy module
import arcpy
import logging, os
from arcpy import env
os.system('CLS')
# Logging Configuration
logFormat = '%(asctime)-15s %(name)-12s %(levelname)-8s %(message)s'
logfile = "export.log"
logging.basicConfig(level=logging.DEBUG, format=logFormat, filename=logfile, filemode='w', encoding = "UTF-8" )
logging.debug("***********************************")
#import cartodb toolbox to python environment
arcpy.ImportToolbox("C:/Python27/ArcGIS10.3/Lib/site-packages/gkudos/esri/toolboxes/CartoDBToolbox.pyt")
# Local variables:
personal_geodatabase_path = "C:/data/geodatabases/my_personal_geodatabase.mdb"
env.workspace = personal_geodatabase_path
# List Datasets
for dataset in arcpy.ListDatasets("*", "Feature"):
logging.debug("*************************************************************************************")
logging.debug("# dataset: "+dataset)
dataset_path = os.path.join(personal_geodatabase_path , dataset)
# List Features
env.workspace = dataset_path
for featureName in arcpy.ListFeatureClasses():
try:
logging.debug( "uploading to cartodb: "+featureName )
# Process: Upload data to CartoDB using Cartodb Toolbox
results = arcpy.CartoDBImportToolbox_CartoDB("cartodb_user", "cartodb_api_key", featureName)
logging.debug( "results from toolbox:")
logging.debug( results )
# Done. Happy Mapping
except Exception as e:
logging.error(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment