Skip to content

Commit

Permalink
time to test with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-basnight committed Oct 10, 2023
1 parent c19872f commit 50e8240
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
65 changes: 33 additions & 32 deletions src/api/db/pathways_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def add_pathway(self, pathway_name, category_name):

def add_bulk_pathways(self, file = '../../web/src/pages/pathwayV2.json'):
# Load the JSON data from a file
json_data = json.load(open(file))
json_data = json.load(open(file, 'r'))

# Connect to the SQL database
conn = self.db_conn.get_connection()
Expand All @@ -48,33 +48,34 @@ def add_bulk_pathways(self, file = '../../web/src/pages/pathwayV2.json'):
try:
# Iterate over each entry in the JSON data
for entry in json_data:
try:
# pathway_name
# category_name

# Insert professor data into the 'professor' table
transaction.execute(
"""
INSERT INTO pathway (
pathway_name,
category_name
for sub in entry['Pathway']:
try:
# pathway_name
# category_name

# Insert professor data into the 'professor' table
transaction.execute(
"""
INSERT INTO pathway (
pathway_name,
category_name
)
VALUES (
NULLIF(%(pathway_name)s, ''),
NULLIF(%(category_name)s, '')
)
ON CONFLICT DO NOTHING;
""",
{
"pathway_name": sub['Name'][0],
"category_name": entry['Category Name'][0]
}
)
VALUES (
NULLIF(%(pathway_name)s, ''),
NULLIF(%(category_name)s, '')
)
ON CONFLICT DO NOTHING;
""",
{
"pathway_name": entry['pathway_name'],
"category_name": entry['category_name']
}
)
except Exception as e:
# Roll back the transaction and return the exception if an error occurs
print("THIS IS THE EXCEPTION:", e)
conn.rollback()
return (False, e)
except Exception as e:
# Roll back the transaction and return the exception if an error occurs
print("THIS IS THE EXCEPTION:", e)
conn.rollback()
return (False, e)
except ValueError as ve:
# Return an error message if the JSON data is invalid
return (False, f"Invalid JSON data: {str(ve)}")
Expand All @@ -90,9 +91,9 @@ def add_bulk_pathways(self, file = '../../web/src/pages/pathwayV2.json'):



# if __name__ == "__main__":
# csv_text = open('../../../src/web/src/pages/pathwayV2.json', 'r')
# pathways = Pathway(connection.db)
# pathways.populate_from_csv(csv_text)
if __name__ == "__main__":
json_text = open('../../../src/web/src/pages/pathwayV2.json', 'r')
pathways = Pathway(connection.db)
# pathways.populate_from_csv(json_text)

#add_bulk_pathways()
pathways.add_bulk_pathways('../../../src/web/src/pages/pathwayV2.json')
10 changes: 4 additions & 6 deletions src/api/tables/pathway_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def loadFields(fields):
printKeys(data)
fields = dict()
loadFields(fields)
'''
for i in fields:
print(i)
for j in fields[i]:
print(' ', j)
'''

for i in data:
for j in i['Pathways']:
print(j["Name"][0], " ", i['Category Name'][0])

0 comments on commit 50e8240

Please sign in to comment.