35 lines
968 B
Python
35 lines
968 B
Python
import csv
|
|
|
|
from ki.models import Language, Skill
|
|
from app import app, db
|
|
|
|
|
|
@app.cli.command("seed")
|
|
def seed():
|
|
|
|
skill_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/skills.csv"
|
|
|
|
with open(skill_seed_file_path) as skills_file:
|
|
skills_csv_reader = csv.DictReader(skills_file)
|
|
|
|
for skill in skills_csv_reader:
|
|
id = int(skill["id"])
|
|
db_skill = Skill.query.get(id)
|
|
|
|
if db_skill is None:
|
|
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
|
|
|
iso_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/iso_639_1.csv"
|
|
|
|
with open(iso_seed_file_path) as iso_file:
|
|
iso_csv_reader = csv.DictReader(iso_file)
|
|
|
|
for iso in iso_csv_reader:
|
|
id = iso["639-1"]
|
|
db_language = Language.query.get(id)
|
|
|
|
if db_language is None:
|
|
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
|
|
|
db.session.commit()
|