-
Notifications
You must be signed in to change notification settings - Fork 0
/
neo4jAISCategory.py
59 lines (47 loc) · 1.9 KB
/
neo4jAISCategory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging
import sys
import csv
import random
import time
from neo4j import GraphDatabase
from neo4j.exceptions import ServiceUnavailable
class App:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
# Don't forget to close the driver connection when you are finished with it
self.driver.close()
@staticmethod
def enable_log(level, output_stream):
handler = logging.StreamHandler(output_stream)
handler.setLevel(level)
logging.getLogger("neo4j").addHandler(handler)
logging.getLogger("neo4j").setLevel(level)
def query_shipping_sites(self,startID,endID):
cCode = "\u0014";
newLine = "\n"
currDB = "iasdb"
with self.driver.session(database=currDB) as session:
# Write transactions allow the driver to handle retries and transient errors
startmillisec = time.time_ns() // 1000000
query = (
"match (cat:Category) with cat skip $startID limit $endID call { with cat match (u:URL) where u.category = cat.name MERGE (u)-[:HAS_CATEGORY]->(cat) } IN TRANSACTIONS OF 1 rows;"
)
result = session.run(query, startID=startID, endID=endID)
#result = session.run(query)
# result = session.write_transaction(self._delete_movies)
for row in result:
x=1
endmillisec = time.time_ns() // 1000000
print(endmillisec - startmillisec)
if __name__ == "__main__":
bolt_url = "neo4j://13.58.250.90:7687"
user = "neo4j"
password = "Amish_2020_Tesla"
App.enable_log(logging.INFO, sys.stdout)
app = App(bolt_url, user, password)
# open file to write out
startSegment = int(sys.argv[1])
endSegment = int(sys.argv[2])
app.query_shipping_sites(startSegment,endSegment)
app.close()