Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from neo4jrestclient.client import GraphDatabase
- import psycopg2
- import csv
- db = GraphDatabase("http://127.0.0.1:7474",username="neo4j", password="1234")
- conn = psycopg2.connect("\
- dbname='bdTrmmTest'\
- user='postgres'\
- host='127.0.0.1'\
- password='1234'\
- ");
- c = conn.cursor()
- c.execute("SELECT latitude, longitude, gid FROM pontos")
- with open("arquivo_destino.csv","wt") as file_:
- writer = csv.writer(file_)
- writer.writerow(("latitude","longitude"))
- records = True
- e = conn.cursor()
- e.execute("SELECT precipitacaoh, gidgeo_fk FROM historico")
- with open("arquivo_destino2.csv","wt") as file2_:
- writer = csv.writer(file2_)
- writer.writerow(("precipitacaoh","gidgeo_fk"))
- records2 = True
- sensorlatlong = db.labels.create("Latitude/Longitude")
- sensorprecip = db.labels.create("Precipitacao")
- while records and records2:
- records = c.fetchmany(100) #pega todos os resultados do select e armazena em uma tupla
- writer.writerows(records)
- records2 = e.fetchmany(100)
- writer.writerows(records)
- #cria todos os sensores os latitude e longitute
- for j in records2:
- s2 = db.nodes.create(precipitacao=j[0])
- sensorprecip.add(s2)
- for i in records:
- if(i[2]==j[1]):
- q = 'MATCH (s:Latitude/Longitude) RETURN s'
- results = db.query(q, returns=(client.Node))
- if (results!=0):
- for r in results:
- if (r[0]["latitude"]==i[0]) and (r[0]["longitude"]==i[1]):
- r[0].relationships.create("MARCOU",s2)
- else:
- s = db.nodes.create(latitude=i[0],longitutde=i[1])
- s.relationships.create("MARCOU",s2)
- else:
- s = db.nodes.create(latitude=i[0],longitutde=i[1])
- sensorlatlong.add(s)
- s.relationships.create("MARCOU",s2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement