Exemple #1
0
def load_db():
    with open('data/teachers.json', 'r', encoding='utf-8') as r:
        get_info = json.load(r)

    for info in get_info:
        teacher = Teacher(name=info['name'], about=info['about'], rating=info['rating'], picture=info['picture'],
                          price=info['price'])
        db.session.add(teacher)

    with open('data/goals.json', 'r', encoding='utf-8') as r:
        goals = json.load(r)

    for goal in goals:
        goal_to_study = Goal(goal_to_study=goal)
        db.session.add(goal_to_study)

    for teacher in get_info:
        teacher_list = teacher['goals']
        for goal in teacher_list:
            query_goal_id = db.session.query(Goal.id).filter(Goal.goal_to_study == goal).first()[0]
            teacher_id = int(teacher['id'] + 1)
            teacher_features = TeacherFeatures(teacher_id=teacher_id, goal_id=query_goal_id)
            db.session.add(teacher_features)

    db.session.commit()
Exemple #2
0
def load_teachers_from_json_to_db():
    with open("teachers.json", "r", encoding='utf8') as f:
        teachers = json.load(f)
        for teacher in teachers:
            new_teacher = Teacher(name=teacher['name'],
                                  picture=teacher['picture'],
                                  price=int(teacher['price']),
                                  about=str(teacher['about']),
                                  rating=float(teacher['rating']))
            db.session.add(new_teacher)
            goals = teacher['goals']
            for k in goals:
                goal = db.session.query(Goal).filter(Goal.short == k).first()
                if goal:
                    new_teacher.goals.append(goal)
            free_times = teacher['free']
            whole_week = data_provider.whole_week()
            for weekday_key, weekday_value in whole_week.items():
                for k, v in free_times[weekday_key].items():
                    if v:
                        h = int(k.split(':')[0])
                        t = datetime.time(h, 00)
                        db.session.add(
                            FreeTimes(teacher=new_teacher,
                                      weekday=weekday_key,
                                      time=t))
        db.session.commit()
Exemple #3
0
def initserver():
    teacherData = xlrd.open_workbook('teacherList.xlsx')
    table = teacherData.sheets()[0]
    teacherName = table.col_values(0)

    for i in range(1, table.nrows):
        teacher = Teacher(name=teacherName[i])
        db.session.add(teacher)

    courseData = xlrd.open_workbook('courseList.xlsx')
    table = courseData.sheets()[0]
    courseName = table.col_values(0)
    beginTime = table.col_values(1)
    duration = table.col_values(2)
    tchId = table.col_values(3)

    for i in range(1, table.nrows):
        timeRes = beginTime[i].split(',')
        course = Course(name=courseName[i],
                        begin_time=time(hour=int(timeRes[0]),
                                        minute=int(timeRes[1]),
                                        second=int(timeRes[2])),
                        duration=int(duration[i]),
                        tch_id=tchId[i])
        db.session.add(course)

    studentData = xlrd.open_workbook('studentList.xlsx')
    table = studentData.sheets()[0]
    stuId = table.col_values(0)
    studentName = table.col_values(1)
    studentDepartment = table.col_values(2)

    for i in range(1, table.nrows):
        student = Student(stu_id=stuId[i],
                          name=studentName[i],
                          department=studentDepartment[i],
                          password='******')
        db.session.add(student)

    scData = xlrd.open_workbook('student_courseList.xlsx')
    table = scData.sheets()[0]
    stuId = table.col_values(0)
    courseId = table.col_values(1)

    for i in range(1, table.nrows):
        sc = Student_Course(stu_id=stuId[i],
                            course_id=courseId[i],
                            attendance_time=0,
                            attendance_state=False)
        db.session.add(sc)

    db.session.commit()

    print("init successfully")
Exemple #4
0
def load_db():
    for teach in teachers:
        goals = json.dumps(teach["goals"])
        free = json.dumps(teach["free"])
        te = Teacher(name=teach["name"],
                     about=teach["about"],
                     rating=teach["rating"],
                     picture=teach["picture"],
                     price=teach["price"],
                     goals=goals,
                     free=free)
        db.session.add(te)
    db.session.commit()
Exemple #5
0
def get_teachers_list():
    with open('teachers.json', 'r') as f:
        contents = f.read()
        teachers_list = json.loads(contents)
    for teacher in teachers_list:
        teacher_add = Teacher(id=teacher['id'],
                              name=teacher['name'],
                              about=teacher['about'],
                              rating=teacher['rating'],
                              picture=teacher['picture'],
                              price=teacher['price'],
                              goals=";".join(teacher["goals"]),
                              free=teacher['free'])

        db.session.add(teacher_add)
        db.session.commit()
def transform_teachers():
    for teacher in teachers:
        goals_bd = []
        for ggoal in teacher['goals']:
            goals_bd.append(
                db.session.query(Goal).filter_by(slug=ggoal).first())
        record = Teacher(name=teacher['name'],
                         about=teacher['about'],
                         rating=teacher['rating'],
                         picture=teacher['picture'],
                         price=teacher['price'],
                         free=teacher['free'],
                         goals=goals_bd)
        db.session.add(record)

    db.session.commit()
Exemple #7
0
def add_teachers():
    for profile in data.teachers:

        teacher = Teacher(
            name=profile['name'],
            about=profile['about'],
            rating=profile['rating'],
            picture=profile['picture'],
            price=profile['price'],
            free=profile['free'],
        )
        for profile_goal in profile['goals']:
            goal = db.session.query(Goal).filter(
                Goal.slug == profile_goal).one()
            teacher.goals.append(goal)
        db.session.add(teacher)
    db.session.commit()
Exemple #8
0
def seed():
    goal_models = [
        Goal(inner_name=k, name=v) for k, v in goals_mapping.items()
    ]
    db.session.add_all(goal_models)

    for t in teachers:
        teacher = Teacher(name=t["name"],
                          about=t["about"],
                          rating=t["rating"],
                          picture=t["picture"],
                          price=t["price"],
                          free=json.dumps(t["free"]))
        for g in t["goals"]:
            for g_model in goal_models:
                if g == g_model.inner_name:
                    teacher.goals.append(g_model)
        db.session.add(teacher)
    db.session.commit()
Exemple #9
0
def load_teachers_to_db():
    """ fill teachers table in database """

    for teacher in teachers:
        free = json.dumps(teacher["free"])
        db_teacher = Teacher(
            id=teacher["id"],
            name=teacher["name"],
            about=teacher["about"],
            rating=teacher["rating"],
            picture=teacher["picture"],
            price=teacher["price"],
            free=free,
        )
        db.session.add(db_teacher)
        for goal in teacher["goals"]:
            db_goal = db.session.query(Goal).filter(Goal.name == goal).first()
            db_teacher.goals.append(db_goal)
    db.session.commit()
def fill_db():
    goals = {}
    for goal_name, goal_display in data.goals.items():
        db_goal = Goal(name=goal_name, name_display=goal_display)
        db.session.add(db_goal)
        goals[goal_name] = db_goal
    for teacher in data.teachers:
        teacher_fill = Teacher(
            name=teacher['name'],
            about=teacher['about'],
            rating=teacher['rating'],
            picture=teacher['picture'],
            price=teacher['price'],
            free=json.dumps(teacher['free']),
        )
        for teach_goal_name in teacher['goals']:
            teacher_fill.goals.append(goals[teach_goal_name])
        db.session.add(teacher_fill)

    db.session.commit()
Exemple #11
0
def json_to_db():

    with open('data/teachers.json', 'r') as teach:
        get_data = json.load(teach)

    for item in get_data:
        gender = item['gender']

        teacher = Teacher(name=item['name'],
                          about=item['about'],
                          rating=item['rating'],
                          picture=item['picture'],
                          price=item['price'],
                          gender=gender)
        db.session.add(teacher)

    for days in get_data[0]['free']:
        day = Day(week_day=days)
        db.session.add(day)

    for time in get_data[0]['free']['mon']:
        times = Time(time=time)
        db.session.add(times)

    for goal in goals:
        goals = Goal(name=goal)
        db.session.add(goals)

    for teacher in get_data:
        teacher_goals = teacher['goals']
        for goal in teacher_goals:
            get_goal_id = db.session.query(
                Goal.id).filter(Goal.name == goal).first()[0]
            teacher_id = int(teacher['id']) + 1
            goal_teacher = GoalTeacher(teacher_id=teacher_id,
                                       goal_id=get_goal_id)
            db.session.add(goal_teacher)

    db.session.commit()
for time in time_have:
    db.session.add(TimeHave(time=time[1]))

for day in days_of_week:
    db.session.add(WeekDay(name_english_long=day[0], name_rus=day[1]))

for goal in goals_pict:
    db.session.add(
        Goal(name_english=goal[0], name_rus=goal[1], picture=goal[2]))
db.session.commit()

for teacher in teachers:
    tek_teacher = Teacher(
        name=teacher["name"],
        about=teacher["about"],
        rating=teacher["rating"],
        picture=teacher["picture"],
        price=teacher["price"],
        free=str(teacher["free"]),
        #        free=json.dumps(teacher["free"]),
    )
    db.session.add(tek_teacher)

    for teacher_goal in teacher["goals"]:
        goal = db.session.query(Goal).filter(
            Goal.name_english == teacher_goal).scalar()
        tek_teacher.goals.append(goal)

db.session.commit()
Exemple #13
0
import data
import json
from app import db, Teacher, Goal
# #script for import json data to db

goals = {
    "travel": "⛱ Для путешествий",
    "study": "🏫 Для учебы",
    "work": "🏢 Для работы",
    "relocate": "🚜 Для переезда"
}

for teach in data.teachers:
    teacher = Teacher(t_id=teach['t_id'],
                      name=teach['name'],
                      about=teach['about'],
                      price=teach['price'],
                      rating=teach['rating'],
                      picture=teach['picture'],
                      free=json.dumps(teach['free']))
    db.session.add(teacher)
    for i in teach['goals']:
        goal = Goal(goal_name=goals[i], teacher=teacher, goal_url=i)
        db.session.add(goal)
db.session.commit()
Exemple #14
0
from app import app
from models import db
db.init_app(app)

with app.app_context():
    db.drop_all()
    db.create_all()
    db.session.commit()

#add sample entries
from app import Teacher, Category, Student
with app.app_context():
    t1 = Teacher("Teacher1","*****@*****.**","password","1234567890","teacher")
    t1.is_admin = True
    t1.verified = True
    db.session.add(t1)
    t2 = Teacher("Teacher2","*****@*****.**","password","0987654321","teacher")
    db.session.add(t2)
    s1 = Student("Shafeeq K","*****@*****.**","password","1234567890","student")
    db.session.add(s1)
    s2 = Student("Ashwin Jayakumar","*****@*****.**","password","1234567890","student")
    db.session.add(s2)
    s3 = Student("Hanzal Salim","*****@*****.**","password","1234567890","student")
    db.session.add(s3)
    s4 = Student("Bharadhwaj CN","*****@*****.**","password","1234567890","student")
    db.session.add(s4)
    c = Category("General")
    db.session.add(c)
    c1 = Category("Embedded Systems")
    db.session.add(c1)
    c2 = Category("Compiler Design")
from app import db, Student, Hod, Teacher


# create Student(name)

sunny = Student("sunny")
arpit = Student("arpit")
db.session.add_all([sunny, arpit])
db.session.commit()

# fetch DATABASE

print(Student.query.all())

sunny = Student.query.filter_by(name='sunny').all()[0]
# create hod
hod1 = Hod("saurin", sunny.id)
# create teachers
teacher1 = Teacher("mihir", sunny.id)
teacher2 = Teacher("yash", sunny.id)
db.session.add_all([hod1, teacher1, teacher2])
db.session.commit()

# Let's now grab rufus again after these additions
sunny = Student.query.filter_by(name='sunny').first()
print(sunny)

# Show toys
sunny.report_Teachers()
Exemple #16
0
#Заполним таблицу целей
if  db.session.query(Goal).get(1):
    print('Вы пытаетесь выполнить инициирующую загрузку целей повторно, очистите таблицы чтобы ее выполнить')
else:
    goals_for_table = get_goals_list()
    for key, value in goals_for_table.items():
        goal_add = Goal(key=key, value=value)
        db.session.add(goal_add)
    db.session.commit()

if  db.session.query(Teacher).get(1):
    print('Вы пытаетесь выполнить инициирующую загрузку преподов повторно, очистите таблицы чтобы ее выполнить')
else:
#Заполним таблицу преподавателей
    teachers_for_table = get_teachers_list()
    for teacher in teachers_for_table:
        teacher_add = Teacher(
            id = teacher['id'],
            name = teacher['name'],
            about = teacher['about'],
            rating = teacher['rating'],
            picture = teacher['picture'],
            price = teacher['price'],
            #goals мы добавим отдельно ниже
            free = teacher['free']
        )
        db.session.add(teacher_add)
        for goal in teacher['goals']:
            goal_filter = db.session.query(Goal).filter(Goal.key == goal).scalar()
            teacher_add.goals.append(goal_filter)
    db.session.commit()
import json
from app import db, Teacher

from data import goals, teachers

add_goals = goals
add_teachers = teachers

# db.create_all()

for t in teachers:
    teacher = Teacher(name=t["name"],
                      about=t["about"],
                      rating=t["rating"],
                      picture=t["picture"],
                      price=t["price"],
                      goals=json.dumps(t["goals"]),
                      free_time=json.dumps(t["free"]))
    db.session.add(teacher)
db.session.commit()
Exemple #18
0
from app import app
from models import db
db.init_app(app)

with app.app_context():
    db.drop_all()
    db.create_all()
    db.session.commit()

#add sample entries
from app import Teacher, Category, Student
with app.app_context():
    t1 = Teacher("Teacher1", "*****@*****.**", "password", "1234567890",
                 "teacher")
    t1.is_admin = True
    t1.verified = True
    db.session.add(t1)
    t2 = Teacher("Teacher2", "*****@*****.**", "password", "0987654321",
                 "teacher")
    db.session.add(t2)
    s1 = Student("Shafeeq K", "*****@*****.**", "password", "1234567890",
                 "student")
    db.session.add(s1)
    s2 = Student("Ashwin Jayakumar", "*****@*****.**", "password",
                 "1234567890", "student")
    db.session.add(s2)
    s3 = Student("Hanzal Salim", "*****@*****.**", "password",
                 "1234567890", "student")
    db.session.add(s3)
    s4 = Student("Bharadhwaj CN", "*****@*****.**", "password",
                 "1234567890", "student")
Exemple #19
0
import json

from app import Teacher, db, Goal, Day
from data import teachers, days, goals

for key, value in days.items():
    day = Day(day_key_en=key, day_value_ru=value)
    db.session.add(day)
db.session.commit()

for key, value in goals.items():
    goal = Goal(goal_key_en=key, goal_value_ru=value)
    db.session.add(goal)
db.session.commit()

for teacher in teachers:
    teacher_record = Teacher(id=teacher['id'],
                             name=teacher['name'],
                             about=teacher['about'],
                             rating=teacher['rating'],
                             picture=teacher['picture'],
                             price=teacher['price'],
                             free=json.dumps(teacher['free']))
    for goal in teacher['goals']:
        goal_record = db.session.query(Goal).filter(
            Goal.goal_key_en == goal).first()
        teacher_record.goals.append(goal_record)
        db.session.add(teacher_record)

db.session.commit()