File size: 4,074 Bytes
70ec80a
abf93af
 
8325b3a
70ec80a
 
 
abf93af
 
70ec80a
431cbef
 
 
 
 
 
 
d8346cb
abf93af
8325b3a
 
 
 
 
 
 
8a43927
 
 
 
 
 
 
 
 
8325b3a
 
abf93af
8325b3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5be4b4f
8325b3a
 
 
 
 
 
 
 
 
 
 
 
 
 
abf93af
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
# app_logic.py
import requests
import json
from py2neo import Graph, Node, Relationship

def run_my_application():
    """
    Fetch and process a remote JSON file.
    Replace this with your real application logic.
    """
    # json_file_path = ["https://arinsight.co/skills/Customer_Service_skills.json", "https://arinsight.co/skills/Computer_Programming_skills.json",
                      # "https://arinsight.co/skills/Data_Science_skills.json", "https://arinsight.co/skills/Communications_skills.json", 
                      # "https://arinsight.co/skills/Cleaning_and_Facilities_skills.json",
                      # "https://arinsight.co/skills/Caregiving_skills.json","https://arinsight.co/skills/Business_Development_and_Sales_skills.json", 
                      # "https://arinsight.co/skills/Arts_and_Design_skills.json", "https://arinsight.co/skills/Architecture_and_Construction_skills.json",
                      # "https://arinsight.co/skills/Civil_Engineering_skills.json"]

    json_file_path = ["https://arinsight.co/skills/Accounting_and_Finance_skills.json"]

    # Connection to Neo4j
    graph = Graph("bolt://20.64.235.115:7687", auth=("neo4j", "123456789"))
    
    # Read the JSON file
    # json_file_path = ["Engineering_skills.json", "Energy and Utilities_skills.json", "Electrical Engineering_skills.json"]
    # graph.delete_all()
    for file in json_file_path:
        # with open(file, "r") as file:
        #     data = json.load(file)
        response = requests.get(file)
            
        #     # Raise an error if the request failed
        response.raise_for_status()
    
        #     # Parse the JSON content
        data = response.json()
    
        # Clear the graph database before starting
        
    
        # Create graph nodes and relationships
        for entry in data:
            primary_skill = entry["Primary Skill"]
            secondary_skill = entry["Secondary Skill"]
            primary_description = entry.get("Description", "")
            educational_alignment = entry.get("Educational Alignment", "")
            curriculum_areas = "; ".join(entry.get("Curriculum Areas", []))
            tertiary_skills = entry["Tertiary Skills"]
    
            # Create or get the Primary Skill node
            primary_node = Node("PrimarySkill", name=primary_skill, description=primary_description)
            graph.merge(primary_node, "PrimarySkill", "name")
    
            # Create the Secondary Skill node
            secondary_node = Node(
                "SecondarySkill",
                name=secondary_skill,
                description=primary_description,
                educational_alignment=educational_alignment,
                curriculum_areas=curriculum_areas,
            )
            graph.merge(secondary_node, "SecondarySkill", "name")
    
            # Relationship: PrimarySkill -> has_secondary -> SecondarySkill
            relationship = Relationship(primary_node, "HAS_SECONDARY", secondary_node)
            graph.merge(relationship)
    
            # Create Tertiary Skills nodes and relationships
            for tertiary_skill in tertiary_skills:
                tertiary_node = Node("TertiarySkill", name=tertiary_skill, description="")
                graph.merge(tertiary_node, "TertiarySkill", "name")
    
                # Relationship: SecondarySkill -> has_tertiary -> TertiarySkill
                tertiary_relationship = Relationship(secondary_node, "HAS_TERTIARY", tertiary_node)
                graph.merge(tertiary_relationship)
    
    return "Graph database has been populated."
    
        
        # for file_url in json_file_paths:
        #     # Fetch the content from the URL
        #     response = requests.get(file_url)
            
        #     # Raise an error if the request failed
        #     response.raise_for_status()
    
        #     # Parse the JSON content
        #     data = response.json()
    
        #     # Assuming you want to return the 'Primary Skill' of the first item
        #     return data[0]['Primary Skill']