/
neo4j.py
175 lines (137 loc) · 6 KB
/
neo4j.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
__author__ = 'vlad'
import py2neo
from py2neo import Graph, Node, Relationship, authenticate
import json
import requests
authenticate("localhost:7474", "neo4j", "1111")
def get_objects(name):
"""
fetches objects from my register
name: method, author, category
returns: dictionary
"""
request = requests.get('http://127.0.0.1:5010/api/' + str(name))
api_data = json.loads(request.text)
#print(request.text)
return api_data["objects"]
def get_objects_art(name):
"""
fetches objects from my register
name: method, author, category
returns: dictionary
"""
request = requests.get('http://127.0.0.1:5020/api/' + str(name))
api_data = json.loads(request.text)
#print(api_data)
return api_data["objects"]
def get_object(name):
"""
fetches objects from my register
name: method, author, category
returns: dictionary
"""
request = requests.get('http://127.0.0.1:5010/api/' + str(name))
api_object = json.loads(request.text)
#print(request.text)
return api_object
def get_objects2(name):
"""
fetches objects from second register
name: experts, documents, commission orders, legal_issues, expertises
returns: dictionary
"""
request = requests.get('http://polar-journey-8507.herokuapp.com/api/' + str(name))
api_data = json.loads(request.text)
return api_data
# categories = get_objects('category')
def import_api_data():
"""
imports data from my register (method and all adjacent) into graph DB
"""
graph = Graph()
# graph.delete_all()
# Uncomment on the first run!
# graph.schema.create_uniqueness_constraint("Method", "id")
# graph.schema.create_uniqueness_constraint("Author", "id")
# graph.schema.create_uniqueness_constraint("Category", "id")
obtajenna = get_objects_art('obtaj')
for api_obtaj in obtajenna:
node_demand= graph.merge_one("Demand", "id", api_obtaj["id"])
node_demand["reason_doc"] = api_obtaj["reason_doc"]
node_demand["cost_size"] = api_obtaj["cost_size"]
for api_author in api_obtaj["borjnuku"]:
node_borjnuk = graph.merge_one("Borjnuk", "id", api_author["id"])
node_borjnuk["name"] = api_author["name"]
node_borjnuk["tel_number"] = api_author["tel_number"]
node_borjnuk.push()
graph.create_unique(Relationship(node_borjnuk, "obtajuetsa", node_demand))
for api_property in api_obtaj["properties"]:
node_property = graph.merge_one("Property", "id", api_property["id"])
node_property["name"] = api_property["name_property"]
node_property["ser_number"] = api_property["ser_number"]
node_property.push()
graph.create_unique(Relationship(node_property, "zakladena", node_demand))
node_demand.push()
demands = get_objects('demand')
for api_demand in demands:
node_demand = graph.merge_one("Demand", "id", api_demand["id"])
node_demand["sum"] = api_demand["sum"]
api_debtor = api_demand["Debtor"]
node_debtor = graph.merge_one("Debtor", "id", api_debtor["id"])
node_debtor["name"] = api_debtor["name"]
api_arbitration = get_object('arbitration/' + str(api_debtor["arbitration_id"]))
#print(api_arbitration.text)
node_arbitration = graph.merge_one("Arbitration", "id", api_arbitration["id"])
node_arbitration["name"] = api_arbitration["name"]
node_arbitration.push()
graph.create_unique(Relationship(node_arbitration, "CONTAINS", node_debtor))
node_debtor.push()
graph.create_unique(Relationship(node_debtor, "CONTAINS", node_demand))
api_creditor = api_demand["Creditor"]
node_creditor = graph.merge_one("Creditor", "id", api_creditor["id"])
node_creditor["name"] = api_creditor["name"]
node_creditor.push()
graph.create_unique(Relationship(node_creditor, "CONTAINS", node_demand))
"""
for api_author in api_method["authors"]:
node_author = graph.merge_one("Author", "id", api_author["id"])
node_author["name"] = api_author["name"]
node_author.push()
graph.create_unique(Relationship(node_author, "WROTE", node_method))
api_category = api_method["category"]
node_category = graph.merge_one("Category", "id", api_category["id"])
node_category["name"] = api_category["name"]
node_category.push()
graph.create_unique(Relationship(node_category, "CONTAINS", node_method))"""
node_demand.push()
def import_api_data2():
authenticate("localhost:7474", "neo4j", "1111")
graph = Graph()
#graph.delete_all()
# Uncomment on the first run!
#graph.schema.create_uniqueness_constraint("Borjnuk", "id")
#graph.schema.create_uniqueness_constraint("Obtaj", "id")
#graph.schema.create_uniqueness_constraint("Property", "id")
obtajenna = get_objects_art('obtaj')
for api_obtaj in obtajenna:
node_obtaj= graph.merge_one("Obtaj", "id", api_obtaj["id"])
node_obtaj["reason_doc"] = api_obtaj["reason_doc"]
node_obtaj["cost_size"] = api_obtaj["cost_size"]
for api_author in api_obtaj["borjnuku"]:
node_borjnuk = graph.merge_one("Borjnuk", "id", api_author["id"])
node_borjnuk["name"] = api_author["name"]
node_borjnuk["tel_number"] = api_author["tel_number"]
node_borjnuk.push()
graph.create_unique(Relationship(node_borjnuk, "obtajuetsa", node_obtaj))
for api_property in api_obtaj["properties"]:
node_property = graph.merge_one("Property", "id", api_property["id"])
node_property["name"] = api_property["name_property"]
node_property["ser_number"] = api_property["ser_number"]
node_property.push()
graph.create_unique(Relationship(node_property, "zakladena", node_obtaj))
node_obtaj.push()
if __name__ == "__main__":
# graph = Graph()
# graph.delete_all()
import_api_data()
#import_api_data2()