Esempio n. 1
0
    def add_category(payload):
        body = request.get_json()
        try:
            category = body.get("category", None)

            if exist(Category, category, "category"):
                abort(422)
            else:
                new = Category(category=category)
                new.insert()
        except:
            abort(422)

        return (jsonify({
            "success": True,
            "added_category_id": new.id,
            "added_category": new.category
        }))
Esempio n. 2
0
    def bulk_add_example_data(payload):
        categories = pd.read_csv("initialdata/categories.csv", sep=";")
        movies = pd.read_csv("initialdata/movies.csv", sep=";")
        questions = pd.read_csv("initialdata/questions.csv", sep=";")
        movie_answers = pd.read_csv("initialdata/question_movie_mapping.csv",
                                    sep=";",
                                    decimal=",")

        #Add example categories
        for i, row in categories.iterrows():
            new = Category(category=row["Category"])
            new.insert()

        #Add example movies
        for i, row in movies.iterrows():
            new = Movie(title=row["title"],
                        description=row["description"],
                        category_id=row["category_id"])
            new.insert()

        #Add example questions
        for i, row in questions.iterrows():
            new = Question(question=row["question"],
                           category_id=row["category_id"],
                           Type=row["Type"])
            new.insert()

        #Add Question Answers
        for i, row in movie_answers.iterrows():
            for question_id in movie_answers.columns[1:]:
                new = QuestionMovie(question_id=question_id,
                                    movie_id=row["movie_id"],
                                    answer=row[question_id])
                new.insert()

        return (jsonify({"success": True}))