-
Notifications
You must be signed in to change notification settings - Fork 8
/
run.py
103 lines (87 loc) · 3.32 KB
/
run.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
import psycopg2
import json
import os
from datetime import datetime
engine = psycopg2.connect(
database="d2kedqtund732q",
user="jdlgewreuvgeqx",
password="d81a731c4930221b6fed9df3271d8f6d88a387d58b15527ee4ec62732f64914e",
host="ec2-54-163-254-204.compute-1.amazonaws.com",
port='5432'
)
print("hi")
print(os.listdir(os.getcwd()))
db_cursor = engine.cursor()
db_cursor.execute("SELECT * FROM database_course")
temp = db_cursor.fetchall()
# courses
courses = []
for x in range(len(temp)):
outerFields = dict()
outerFields["info"] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
outerFields["pk"] = temp[x][0]
outerFields["model"] = "database.course"
innerFields = dict()
innerFields["prefix"] = temp[x][1]
innerFields["ID"] = temp[x][2]
innerFields["name"] = temp[x][3]
innerFields["description"] = temp[x][4]
innerFields["HI"] = temp[x][5]
innerFields["CI"] = temp[x][6]
innerFields["DI"] = temp[x][7]
innerFields["major_restrictive"] = temp[x][8]
innerFields["fall"] = temp[x][9]
innerFields["spring"] = temp[x][10]
innerFields["summer"] = temp[x][11]
outerFields["fields"] = innerFields
courses.append(outerFields)
root_folder_jsonfiles = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/HASSPathways/JSONfiles/"
courseDataFile = open(root_folder_jsonfiles+"courses.json", 'w')
courseDataFile.truncate()
courseDataFile.write(json.dumps(courses, sort_keys=True, indent=4))
courseDataFile.close()
# with open("./JSONfiles/courses.json", "w") as outfile:
# json.dump(courses, outfile, sort_keys=True, indent=4)
db_cursor = engine.cursor()
db_cursor.execute("SELECT * FROM database_pathway")
temp = db_cursor.fetchall()
# pathways
pathways = []
for x in range(len(temp)):
outerFields = dict()
outerFields["info"] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
outerFields["pk"] = temp[x][0]
outerFields["model"] = "database.pathway"
innerFields = dict()
innerFields["pathName"] = temp[x][1]
innerFields["pathDescript"] = temp[x][2]
innerFields["priority1"] = []
innerFields["priority2"] = []
innerFields["priority3"] = []
db_cursor = engine.cursor()
db_cursor.execute("SELECT * FROM database_pathway_priority1")
priority1 = db_cursor.fetchall()
for y in priority1:
if y[1] == temp[x][0]:
innerFields["priority1"].append(y[2])
db_cursor = engine.cursor()
db_cursor.execute("SELECT * FROM database_pathway_priority2")
priority2 = db_cursor.fetchall()
for y in priority2:
if y[1] == temp[x][0]:
innerFields["priority2"].append(y[2])
db_cursor = engine.cursor()
db_cursor.execute("SELECT * FROM database_pathway_priority3")
priority3 = db_cursor.fetchall()
for y in priority3:
if y[1] == temp[x][0]:
innerFields["priority3"].append(y[2])
outerFields["fields"] = innerFields
pathways.append(outerFields)
root_folder_jsonfiles = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/HASSPathways/JSONfiles/"
pathwayDataFile = open(root_folder_jsonfiles+"pathways.json", 'w')
pathwayDataFile.truncate()
pathwayDataFile.write(json.dumps(pathways, sort_keys=True, indent=4))
pathwayDataFile.close()
# with open("./JSONfiles/pathways.json", "w") as outfile:
# json.dump(pathways, outfile, sort_keys=True, indent=4)