khurrameycon commited on
Commit
8325b3a
·
verified ·
1 Parent(s): 2db5146

Update app_logic.py

Browse files
Files changed (1) hide show
  1. app_logic.py +64 -11
app_logic.py CHANGED
@@ -1,6 +1,7 @@
1
  # app_logic.py
2
  import requests
3
  import json
 
4
 
5
  def run_my_application():
6
  """
@@ -9,16 +10,68 @@ def run_my_application():
9
  """
10
  json_file_paths = ["https://arinsight.co/skills/Education%20and%20Training_skills.json"]
11
 
12
- for file_url in json_file_paths:
13
- # Fetch the content from the URL
14
- response = requests.get(file_url)
 
 
 
 
 
 
 
 
15
 
16
- # Raise an error if the request failed
17
- response.raise_for_status()
18
-
19
- # Parse the JSON content
20
- data = response.json()
21
-
22
- # Assuming you want to return the 'Primary Skill' of the first item
23
- return data[0]['Primary Skill']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
1
  # app_logic.py
2
  import requests
3
  import json
4
+ from py2neo import Graph, Node, Relationship
5
 
6
  def run_my_application():
7
  """
 
10
  """
11
  json_file_paths = ["https://arinsight.co/skills/Education%20and%20Training_skills.json"]
12
 
13
+ # Connection to Neo4j
14
+ graph = Graph("bolt://20.64.235.115:7687", auth=("neo4j", "123456789"))
15
+
16
+ # Read the JSON file
17
+ # json_file_path = ["Engineering_skills.json", "Energy and Utilities_skills.json", "Electrical Engineering_skills.json"]
18
+ # graph.delete_all()
19
+ for file in json_file_path:
20
+ with open(file, "r") as file:
21
+ data = json.load(file)
22
+
23
+ # Clear the graph database before starting
24
 
25
+
26
+ # Create graph nodes and relationships
27
+ for entry in data:
28
+ primary_skill = entry["Primary Skill"]
29
+ secondary_skill = entry["Secondary Skill"]
30
+ primary_description = entry.get("Description", "")
31
+ educational_alignment = entry.get("Educational Alignment", "")
32
+ curriculum_areas = "; ".join(entry.get("Curriculum Areas", []))
33
+ tertiary_skills = entry["Tertiary Skills"]
34
+
35
+ # Create or get the Primary Skill node
36
+ primary_node = Node("PrimarySkill", name=primary_skill, description=primary_description)
37
+ graph.merge(primary_node, "PrimarySkill", "name")
38
+
39
+ # Create the Secondary Skill node
40
+ secondary_node = Node(
41
+ "SecondarySkill",
42
+ name=secondary_skill,
43
+ description=primary_description,
44
+ educational_alignment=educational_alignment,
45
+ curriculum_areas=curriculum_areas,
46
+ )
47
+ graph.merge(secondary_node, "SecondarySkill", "name")
48
+
49
+ # Relationship: PrimarySkill -> has_secondary -> SecondarySkill
50
+ relationship = Relationship(primary_node, "HAS_SECONDARY", secondary_node)
51
+ graph.merge(relationship)
52
+
53
+ # Create Tertiary Skills nodes and relationships
54
+ for tertiary_skill in tertiary_skills:
55
+ tertiary_node = Node("TertiarySkill", name=tertiary_skill, description="")
56
+ graph.merge(tertiary_node, "TertiarySkill", "name")
57
+
58
+ # Relationship: SecondarySkill -> has_tertiary -> TertiarySkill
59
+ tertiary_relationship = Relationship(secondary_node, "HAS_TERTIARY", tertiary_node)
60
+ graph.merge(tertiary_relationship)
61
+
62
+ return "Graph database has been populated."
63
+
64
+
65
+ # for file_url in json_file_paths:
66
+ # # Fetch the content from the URL
67
+ # response = requests.get(file_url)
68
+
69
+ # # Raise an error if the request failed
70
+ # response.raise_for_status()
71
+
72
+ # # Parse the JSON content
73
+ # data = response.json()
74
+
75
+ # # Assuming you want to return the 'Primary Skill' of the first item
76
+ # return data[0]['Primary Skill']
77