Skip to content

Instantly share code, notes, and snippets.

@jorgebastida
Forked from anonymous/gist:5281610
Created March 31, 2013 19:03
Show Gist options
  • Save jorgebastida/5281621 to your computer and use it in GitHub Desktop.
Save jorgebastida/5281621 to your computer and use it in GitHub Desktop.
# antes de importar nada
from gevent import monkey
monkey.patch_socket()
import gevent
from gevent import socket
def InsertData(line, value):
data = line.split(',')
try:
res = cl.sql("select cartodb_id from hydrocarbons where the_geom=ST_SetSRID(ST_Point("+data[0]+", "+data[1]+"),4326) and price_date ='"+today+"'")
if res['total_rows'] == 1:
try:
cl.sql("update hydrocarbons set "+key+"_price="+data[3]+" where cartodb_id="+str(res['rows'][0]['cartodb_id'])+"")
print "updating new value of" + value
except CartoDBException as e:
print ("some error ocurred", e)
else:
try:
cl.sql("insert into hydrocarbons (the_geom, a_display, "+key+"_price, price_date) values (ST_SetSRID(ST_Point("+data[0]+", "+data[1]+"),4326), '"+data[2]+"', "+data[3]+", '"+today+"')")
print "inserting new value of" + value
except CartoDBException as e:
print ("some error ocurred", e)
except CartoDBException as e:
print ("some error ocurred", e)
jobs = [gevent.spawn(InsertData, line, value) for line in rline]
gevent.joinall(jobs, timeout=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment