-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathseed_database.py
80 lines (61 loc) · 2.19 KB
/
seed_database.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
"""This file Loads data from json file and seed the tables"""
import json
import os
import crud
import database_model
from app import app
database_model.connect_to_db(app, "resume")
database_model.db.drop_all()
database_model.db.create_all() # create database structure
with open("data/user.json") as file:
user_file = json.loads(file.read())
db_users = []
for user in user_file:
name = user["name"]
phone = user["phone"]
email = user["email"]
resume_order = user["resume_order"]
save_user_to_db = crud.create_user(name, phone, email, resume_order)
db_users.append(save_user_to_db)
database_model.db.session.add_all(db_users)
with open("data/education.json") as education_file:
educations = json.loads(education_file.read())
education_list = []
for education in educations:
course = education["course"]
school = education["school"]
start_date = education["start_date"]
end_date = education["end_date"]
grade = education["grade"]
logo = education["logo"]
save_education_to_db = crud.create_education(
course, school, start_date, end_date, grade, logo
)
education_list.append(save_education_to_db)
database_model.db.session.add_all(education_list)
with open("data/experience.json") as experience_file:
experiences = json.loads(experience_file.read())
experience_list = []
for experience in experiences:
title = experience["title"]
company = experience["company"]
start_date = experience["start_date"]
end_date = experience["end_date"]
description = experience["description"]
logo = experience["logo"]
save_experience_to_db = crud.create_experience(
title, company, start_date, end_date, description, logo
)
experience_list.append(save_experience_to_db)
database_model.db.session.add_all(experience_list)
with open("data/skills.json") as skill_file:
skills = json.loads(skill_file.read())
skill_list = []
for skill in skills:
name = skill["name"]
proficiency = skill["proficiency"]
logo = skill["logo"]
save_skill_to_db = crud.create_skill(name, proficiency, logo)
skill_list.append(save_skill_to_db)
database_model.db.session.add_all(skill_list)
database_model.db.session.commit()