-
-
Save jorgebastida/5281621 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
# 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