def check_positions():
    if request.method == 'GET':
        return render_template('check_positions.html')
    else:
        ticker_symbol = request.form.get('ticker_symbol')
        check_positions = orm.User('simbuilder').check_positions(ticker_symbol)
        return render_template('check_positions.html', msg= check_positions)  
def pnl_position():
    if request.method == 'GET':
        return render_template('pnl_position.html')
    else:
        user_submission = request.form.get('ticker_symbol')
        ticker_PNL = orm.User('simbuilder').mtm_pnl(user_submission)
        return render_template('pnl_position.html', msg=ticker_PNL, ticker_symbol = user_submission)  
Exemple #3
0
def post_signup(body):
    user = orm.User(nickname=body.get('nickname', None),
             email=body.get('email', None),
             password_hash=body.get('password_hash', None))

    db_session.add(user)
    db_session.commit()

    return user.dump()
def sell():
    if request.method == 'GET':
        return render_template('sell.html')
    else:
        ticker_symbol = request.form.get('ticker_symbol')
        order_quantity = request.form.get('order_quantity')
        print (ticker_symbol, order_quantity)
        confirmation_message = orm.User('simbuilder').sell(ticker_symbol, order_quantity)             ## username is hardcoded to simbuilder
        return render_template('confirmation.html', msg = confirmation_message)
Exemple #5
0
def register():
    name=request.form.get('name').replace(' ','')
    affiliation=request.form.get('affiliation')
    email=request.form.get('email')
    groups=request.form.getlist('group[]')
    user=orm.User(user_db=get_db(app.config['DB_NAME_USERS']),user=name,groups=groups,email=email,affiliation=affiliation)
    print(user.json())
    print(user.status)
    return jsonify(message=user.status['message']), user.status['http_code']
Exemple #6
0
def put_user(user_id, user):
    p = db_session.query(orm.User).filter(orm.User.id == user_id).one_or_none()
    user['id'] = user_id
    if p is not None:
        logging.info('Updating user %s..', user_id)
        p.update(**user)
    else:
        logging.info('Creating user %s..', user_id)
        user['created'] = datetime.datetime.utcnow()
        db_session.add(orm.User(**user))
    db_session.commit()
    return NoContent, (200 if p is not None else 201)
Exemple #7
0
async def send_hello(message: types.message):
    with Session(database.engine) as session:
        try:
            session.add(orm.User(user_id=message.from_user.id))
            session.commit()
        except IntegrityError:
            await message.answer(
                "Hey! I already know you. Use /help command to get more information"
            )
            return
        await message.answer(
            "Hello! I am Morning Paper Bot. Currently under development.\n"
            "Type /help to get more information")
Exemple #8
0
def message_router(update: Update, context: CallbackContext):
    # 1. Check if user exists
    session = orm.new_session()
    user = orm.User.get_by_chat_id(session, update.message.chat_id)

    if user is None:
        # If not - create user and start registration process
        user = orm.User(chat_id=update.message.chat_id)
        user.push(session)
        session.commit()
        session.close()

        dialogue = dialogues.Registration(update.message, context)
        dialogue.start()

        return

    # 2. Check if user has a dialogue
    if user.current_dialogue is None:
        # If not - check if answer is from main menu and start dialogue
        if update.message.text in main_menu.keys():
            dialogue_class = dialogues.get_dialogue_class(
                main_menu[update.message.text])
            dialogue = dialogue_class(update.message, context)
            dialogue.start()

        # If answer is not from menu - ask again
        else:
            update.message.reply_text(
                'Выберите действие:',
                reply_markup=dialogues.Dialogue.reply_markups['main_menu'])

        return

    # 3. Route a message to correct dialogue
    dialogue_type = user.current_dialogue.type
    session.close()
    dialogue_class = dialogues.get_dialogue_class(dialogue_type)
    dialogue = dialogue_class(update.message, context)
    dialogue.route_message()
Exemple #9
0
def add_new_user(user_name):
    db = orm.User(user_name)
    response = db.insert_new_user()
    return response
Exemple #10
0
async def process_postback(messaging, postback):
    # 1. user
    # 2. state
    # 3. get all sub states
    # 4. compare postback in sub states
    # 5. response
    global headers, params
    db = orm.SessionLocal()

    user_fb_id = messaging['sender']['id']
    user = db.query(
        orm.User).filter(orm.User.fb_id == user_fb_id).one_or_none()
    if user is None:
        db_user = orm.User()
        db_user.fb_id = user_fb_id
        db.add(db_user)
        db.commit()
        await init_menu(user_fb_id, headers, params)
        user = db_user

    payload = postback['payload']
    print("process_postback's payload is :", payload)
    if payload == 'QUICK_REPLY':
        user.state_id = sqlalchemy.sql.null()
        db.add(user)
        db.commit()

    sub_states = db.query(
        orm.State).filter(orm.State.parent_id == user.state_id).all()
    print("process postback's sub_state is :", sub_states)
    if not sub_states:
        state_function = db.query(
            orm.State).filter(orm.State.name == payload).one_or_none()
        if state_function:
            print("process_postback's function is: ", state_function.function)
            function = mapping.get(state_function.function)
            await function(sender_id=user.fb_id,
                           headers=headers,
                           params=params)
            db.close()
            return
    sub_state_names = [sub_state.name for sub_state in sub_states]
    print("sub_state_names: ", sub_state_names, payload)
    if payload in sub_state_names:
        # Change user state to input state
        state = db.query(orm.State).filter(orm.State.name == payload).first()
        user.state_id = state.id
        db.add(user)
        db.commit()
        # Execute state function
        print(state.function)
        if state.function:
            if not db.query(orm.State).filter(
                    orm.State.parent_id == user.state_id).all():
                user.state_id = sqlalchemy.sql.null()
            db.add(user)
            db.commit()
            function = mapping.get(state.function)
            await function(sender_id=user.fb_id,
                           headers=headers,
                           params=params,
                           name=payload)
            db.close()
            return
        sub_states = db.query(
            orm.State).filter(orm.State.parent_id == user.state_id).all()
        print(sub_states)
        # Find next states
        data = {
            "recipient": {
                "id": user.fb_id
            },
            "messaging_type": "RESPONSE",
            "message": {
                "text":
                state.prompt or state.label,
                "quick_replies": [{
                    "content_type": "text",
                    "title": sub_state.label,
                    "payload": sub_state.name,
                } for sub_state in sub_states]
            }
        }
        print(data)
        resp = requests.post('https://graph.facebook.com/v10.0/me/messages',
                             headers=headers,
                             params=params,
                             json=data)
        print(resp, resp.content.decode('utf-8'))
    db.close()
Exemple #11
0
async def process_message(messaging, message):
    # 1. user
    # 2. state
    # 3. get all sub states
    # 4. compare message in sub states
    # 5. response
    global headers, params
    db = orm.SessionLocal()
    user_fb_id = messaging['sender']['id']
    user = db.query(
        orm.User).filter(orm.User.fb_id == user_fb_id).one_or_none()
    if user is None:
        db_user = orm.User()
        db_user.fb_id = user_fb_id
        db.add(db_user)
        db.commit()
        await init_menu(user_fb_id, headers, params)
        user = db_user
    sub_states = db.query(
        orm.State).filter(orm.State.parent_id == user.state_id).all()
    if not sub_states:
        print(message)
        if 'text' in message:
            payload = message['text']

    sub_state_names = [sub_state.name for sub_state in sub_states[::-1]]
    # NTUB_ROOM_LOCATION
    payload = None
    if 'quick_reply' in message:
        payload = message['quick_reply']['payload']
        label = message['text']
    elif 'text' in message:
        payload = message['text']

    state = db.query(
        orm.State).filter(orm.State.id == user.state_id).one_or_none()
    if payload in sub_state_names:
        state = db.query(orm.State).filter(orm.State.name == payload).first()
        # Change user state to input state
        user.state_id = state.id
        db.add(user)
        db.commit()
        # Execute state function
        print(state.function)
        if state.function:
            if not db.query(orm.State).filter(
                    orm.State.parent_id == user.state_id).all():
                user.state_id = sqlalchemy.sql.null()
            db.add(user)
            db.commit()
            function = mapping.get(state.function)
            await function(sender_id=user.fb_id,
                           headers=headers,
                           params=params,
                           name=payload,
                           label=label)
            db.close()
            return
        # Find next states
        await quick_replies(user.fb_id, headers, params, state)
    elif state and state.is_input and state.function:
        print('in ', state, state.is_input, state.function)
        function = mapping.get(state.function)
        await function(sender_id=user.fb_id,
                       headers=headers,
                       params=params,
                       name=payload)
        if not db.query(
                orm.State).filter(orm.State.parent_id == user.state_id).all():
            user.state_id = sqlalchemy.sql.null()
        db.add(user)
        db.commit()
        db.close()
        return
    else:
        message = payload
        print("call main.py--------------------")
        print("message", message)
        await detect_action(message,
                            sender_id=user.fb_id,
                            headers=headers,
                            params=params)
        return

    db.close()
def see_portfolio():
    if request.method == 'GET':
        return render_template('see_portfolio.html')
    else:
        print ('see_portfolio')
        return render_template('see_portfolio.html', msg = orm.User("simbuilder").see_portfolio("simbuilder"))