forked from dnguy262/csc366-project-raythked
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate.py
More file actions
64 lines (49 loc) · 1.98 KB
/
populate.py
File metadata and controls
64 lines (49 loc) · 1.98 KB
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
import subprocess
from os.path import exists
from os import chdir
from excel_parse.manager import executeQuery
# This file populates our DB w/ excel and ONET data.
def executeFile(filename):
with open(filename, 'r') as file:
queries = [q.strip('\n') for q in file.readlines()]
# Handling another format for the file
if 'onet' in filename:
queries = [' '.join(queries)]
for query in queries:
try:
executeQuery(query)
except:
print(query)
executeQuery(query)
print(f"Done inserting from {filename}")
def main():
# Drop tables (we don't support updates yet)
chdir("excel_parse") # change directory
subprocess.run("python3 manager.py -d".split())
# Creates tables
subprocess.run("python3 manager.py -c".split())
filenames = ['./excel_parse/insert_stms_excel.sql', './onet-parse/sql/onet-job-info.sql', './onet-parse/sql/onet-job-profiles.sql']
chdir("../") # come back to original directory
# Creates insert file from excel, if doesn't exists
if not exists(filenames[0]):
subprocess.run("python3 excel_parse/parse.py".split())
# Creates insert file from ONET, if doesn't exists
if not exists(filenames[1]) or not exists(filenames[2]):
chdir("./onet_parse")
subprocess.run("cd ./onet-parse && yarn run parse:script".split())
chdir("../")
# Executing insert stmts
for filename in filenames:
try:
executeFile(filename)
except:
print(f"error in {filename}")
# Creates insert file from onet excel, if doesn't exist.
# This needs to have tables (such as Profiles) already populated.
if not exists('excel_parse/insert_stms_onet.sql'):
chdir("./excel_parse")
subprocess.run("python3 parse_onet_mapping.py".split())
chdir("../")
executeFile('./excel_parse/insert_stms_onet.sql')
if __name__ == '__main__':
main()