Hello,
I am a beginner at python and want to modify this API to write both a kmz file and a tiff file to my computer. Currently if it posts as kmz, it only pulls kmz.
Andrew
I am a beginner at python and want to modify this API to write both a kmz file and a tiff file to my computer. Currently if it posts as kmz, it only pulls kmz.
import requests, csv, sys, os, time, json server="https://xxxxxxxx.com" if len(sys.argv) == 1: print "ERROR: Need a .csv file\neg. python coverage.py mydata.csv" quit() if not os.path.exists("calculations"): os.makedirs("calculations") # Open CSV file csvfile = csv.DictReader(open(sys.argv[1])) n=0 for row in csvfile: # Pause script. Important otherwise server will ban you. time.sleep(1) start_time = time.time() # Stopwatch start #print row r = requests.post(server+"/API/area", data=row) print r.text #try: j = json.loads(r.text) if 'kmz' in j: #print j['kmz'] r = requests.get(j['kmz']) fn="calculations"+os.sep+str(row['nam'])+".kmz" file = open(fn,"wb") file.write(r.content) file.close() print "Saved to %s" % fn if 'shp' in j: #print j['kmz'] r = requests.get(j['shp']) fn="calculations"+os.sep+str(row['nam'])+".shp.zip" file = open(fn,"wb") file.write(r.content) file.close() print "Saved to %s" % fn elapsed = round(time.time() - start_time,1) # Stopwatch print "Elapsed: "+str(elapsed)+"s" n=n+1Let me know if you can guide me. Thanks,
Andrew