Last active
December 15, 2015 02:55
-
-
Save nygeog/58208e3db5750927cb79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import zipfile | |
import glob | |
#EDIT ONLY THESE TWO VARIABLES | |
cdbU = <cartoDBusername> | |
cdbK = <cartoDBapikey> | |
shpFolder = 'data' | |
theSHP = [os.path.basename(x) for x in glob.glob(shpFolder+'/*.shp')][0] # find filename of the first file in folder w/ .shp using glob | |
theSHPname = theSHP.replace('.shp','') | |
def zipYourSHP(src, dst): | |
zf = zipfile.ZipFile("%s.zip" % (dst), "w", zipfile.ZIP_DEFLATED) | |
abs_src = os.path.abspath(src) | |
for dirname, subdirs, files in os.walk(src): | |
for filename in files: | |
absname = os.path.abspath(os.path.join(dirname, filename)) | |
arcname = absname[len(abs_src) + 1:] | |
print 'zipping %s as %s' % (os.path.join(dirname, filename), | |
arcname) | |
zf.write(absname, arcname) | |
zf.close() | |
print theSHPname, ' ...is the name of your shapefile.' | |
zipYourSHP(shpFolder, 'data_to_cdb') | |
impCMD = "python cartodb-utils.py import -f data_to_cdb.zip -k "+cdbK+" -u "+cdbU | |
os.system(impCMD) #runs the system command | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment