24by7 / app_logic.py
khurrameycon's picture
Update app_logic.py
d8346cb verified
raw
history blame
4.07 kB
# 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']