Exemplo n.º 1
0
    def nouns():
        file = open("nouns.txt", "r")
        word_count = 0
        for line in file:
            if Word.query.filter_by(word=line.rstrip()).count() == 0:
                dbWord = Word(word=line.rstrip())
                dbWord.save()
                word_count += 1

        file = open("actions.txt", "r")
        action_count = 0
        for line in file:
            if Action.query.filter_by(action=line.rstrip()).count() == 0:
                dbAction = Action(action=line.rstrip())
                dbAction.save()
                action_count += 1

        file = open("categories.txt", "r")
        category_count = 0
        for line in file:
            if Category.query.filter_by(name=line.rstrip()).count() == 0:
                dbCategory = Category(name=line.rstrip())
                dbCategory.save()
                category_count += 1

        return jsonify({
            "Words Added": word_count,
            "Actions Added": action_count,
            "Categories Added": category_count
        })
Exemplo n.º 2
0
    def create_action():
        token = str(request.json.get('token', ''))
        action = str(request.json.get('action', ''))
        user = User.query.filter_by(token=token)

        if user.count() > 0:
            if Action.query.filter_by(action=action).count() == 0:
                action = Action(action=action)
                action.save()
                obj = {
                    'id': action.id,
                    'action': action.action,
                }
                new_user_action = user_actions.insert().values(
                    user_id=user[0].id, action_id=action.id)
                db.session.execute(new_user_action)
                db.session.commit()
                response = jsonify(obj)
                response.status_code = 201
                return response
            else:
                abort(
                    make_response(
                        jsonify(message="You already have that action!"), 404))
        else:
            abort(make_response(jsonify(message="Invalid user token."), 404))
Exemplo n.º 3
0
    def setUp(self):
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client
        from app.models import User, Category, Action, Idea

        with self.app.app_context():
            db.create_all()

            user = User(first_name="Ryan",
                        last_name="Hantak",
                        email="*****@*****.**",
                        password="******")
            user.save()

            cat1 = Category(name="Finance")
            cat1.save()
            cat2 = Category(name="Education")
            cat2.save()
            cat3 = Category(name="Tech")
            cat3.save()

            action1 = Action(action="Create an app")
            action1.save()
            action2 = Action(action="Draft an ad campaign")
            action2.save()

            idea1 = Idea(
                user_id=user.id,
                random_word="Skate",
                action_id=action2.id,
                is_genius=True,
                question=
                "Create an ad campaign to sell a book about financial literacy.",
                response=
                "Two friends in a roller derby match are having a conversation about how they're investing their money, one tells the other about what they learned from the book and the second person is so impressed they want to buy it."
            )
            idea1.save()
            idea2 = Idea(
                user_id=user.id,
                random_word="Bird",
                action_id=action1.id,
                is_genius=False,
                question="Create an app people use to trade stocks",
                response=
                "Make it easy to trade stocks mobile, charge a monthly fee so people don't feel like each trade costs them extra money and offer daily articles to encourage them to keep checking."
            )
            idea2.save()

            user.categories.append(cat1)
            user.categories.append(cat2)
            user.categories.append(cat3)

            user.actions.append(action1)
            user.actions.append(action2)

            idea1.categories.append(cat1)
            idea1.categories.append(cat2)

            idea2.categories.append(cat1)
            idea2.categories.append(cat3)

            db.session.add_all([idea1, idea2])
            db.session.commit()

            global user_token
            user_token = User.query.filter_by(
                email='*****@*****.**').first().token