Example #1
0
def bank():
    if not session.has_key('user'):
        return redirect(url_for('login'))
    d=session['user']
    soul=utils.get_soul(d)
    b=100-soul
    money=utils.get_money(d)
    if request.method=="GET":
        return render_template('bank.html', d=d, soul=soul, b=b, money=money)
    elif request.method=="POST":
        button=request.form["button"]
        if button=="Sell":
            try:
                amt_sell=int(request.form['selling'])
                if amt_sell>100 or amt_sell<0 or amt_sell>soul:
                    return render_template("bank1.html",d=d,soul=soul,b=b,money=money)
                value=utils.sell_soul(d,amt_sell)
                return redirect(url_for("bank"))
            except Exception:
                return render_template("bank1.html",d=d,soul=soul,b=b,money=money)
        elif button=="Buy":
            try:
                amt_buy=int(request.form['buying'])
                if amt_buy>100 or amt_buy<0 or amt_buy>b:
                    return render_template("bank1.html",d=d,soul=soul,b=b,money=money)
                value=utils.buy_soul(d,amt_buy)
                return redirect(url_for("bank"))
            except Exception:
                return render_template("bank1.html",d=d,soul=soul,b=b,money=money)
    return redirect(url_for("profile"))
Example #2
0
 def to_pay(self, order):
     """
     send money to another person bill
     :param order: Order
     :return: None
     """
     money = get_money(order.total)
     print(f'{self.name} give ${money}')
     self._bill -= money
     print(f'{self.name} bill status ${self._bill}')
     order.waiter.get_payment(money, self)
Example #3
0
def profile():
    if not session.has_key('user'):
        return redirect(url_for('login'))
    elif request.method=="GET":
        d=session['user']
        money=utils.get_money(d)
        stock=utils.get_stocks(d)[0]
        soul=utils.get_soul(d)
        gain=utils.get_stocks(d)[1]
        total=money+gain
        return render_template('profile.html',d=d,money=money,stock=stock,soul=soul,gain=gain,total=total)
    return redirect(url_for('profile'))
Example #4
0
def message_handler(message):
    user_id: str = str(message.from_user.id)

    def send_message(message, reply_markup=None):
        bot.send_message(user_id, message, reply_markup=reply_markup)

    if message.text == "Регистрация":
        if not utils.id_exists(user_id):
            send_message("Ваш id - " + user_id + ". " +
                         "Для того, чтобы установить пароль, введите:" +
                         "\n\nnew - *ваш новый пароль*")
        else:
            send_message("Пользователь с id " + user_id + " уже существует. ",
                         reply_markup=keyboards.login_or_register())

    elif "new" in message.text:
        utils.set_user(user_id, message.text)
        send_message("Регистрация завершена успешно.")

    elif message.text == "Вход":
        if utils.id_exists(user_id):
            send_message("Ваш id: " + user_id + ". " +
                         "\n\nВведите пароль (pass - *ваш пароль*):")
        else:
            send_message("Вы ещё не зарегестрированы.",
                         reply_markup=keyboards.login_or_register())

    elif "pass" in message.text:
        password = re.search(r'\S+$', message.text).group(0)
        if password == utils.get_password(user_id):
            send_message("Вы вошли в систему.",
                         reply_markup=keyboards.main_menu())
        else:
            send_message("Неверный пароль. Повторите попытку.")

    elif message.text == "Новая операция":
        bot.send_message(user_id,
                         "Выберите операцию.",
                         reply_markup=keyboards.operations())

    ############### FOR CASH ###############

    elif message.text == "Пополнить 💵":
        cash, card = utils.get_money(user_id)
        send_message("Текущий баланс: " + "\nНаличные - " + str(cash) +
                     "\nКарта - " + str(card) + "\n\nВведите сумму:"
                     "\n\n+$ *ваша сумма*")

    elif "+$" in message.text:
        sum = float(re.search(r'\S+$', message.text).group(0))
        result = utils.add_cash(user_id, sum)
        cash, card = utils.get_money(user_id)
        send_message(result + "\n\nТекущий баланс: " + "\nНаличные - " +
                     str(cash) + "\nКарта - " + str(card))

    elif message.text == "Списать 💵":
        cash, card = utils.get_money(user_id)
        send_message("\n\nТекущий баланс: " + "\nНаличные - " + str(cash) +
                     "\nКарта - " + str(card) + "\n\nВведите сумму:"
                     "\n\n-$ *ваша сумма*")

    elif "-$" in message.text:
        sum = float(re.search(r'\S+$', message.text).group(0))
        result = utils.subtract_cash(user_id, sum)
        cash, card = utils.get_money(user_id)
        send_message(result + "\n\nТекущий баланс: " + "\nНаличные - " +
                     str(cash) + "\nКарта - " + str(card))

    elif message.text == "Изменить 💵":
        pass

    ########################################

    ############### FOR CARD ###############
    elif message.text == "Пополнить 💳":
        send_message("Введите сумму:" "\n\n++ *ваша сумма*")

    elif "++" in message.text:
        sum = float(re.search(r'\S+$', message.text).group(0))
        result = utils.add_card(user_id, sum)
        cash, card = utils.get_money(user_id)
        send_message(result + "\n\nТекущий баланс: " + "\nНаличные - " +
                     str(cash) + "\nКарта - " + str(card))

    elif message.text == "Списать 💳":
        send_message("Введите сумму:" "\n\n-- *ваша сумма*")

    elif "--" in message.text:
        sum = float(re.search(r'\S+$', message.text).group(0))
        result = utils.subtract_card(user_id, sum)
        cash, card = utils.get_money(user_id)
        send_message(result + "\n\nТекущий баланс: " + "\nНаличные - " +
                     str(cash) + "\nКарта - " + str(card))

    elif message.text == "Изменить 💳":
        pass

    ########################################

    elif message.text == "Баланс 💰":
        cash, card = utils.get_money(user_id)
        send_message("Наличные: " + str(cash) + "." + "\nКарта: " + str(card) +
                     ".")

    elif message.text == "О боте 🤖":
        send_message("Раздел находится на стадии разработки.")
        # TODO info, how to use bot

    elif message.text == "Разработчик 👼":
        send_message("Лев Красовский" + "\n@lkrasovsky" +
                     "\n\nМинск, Беларусь")
Example #5
0
# same shit here
OtherUtils.utils_one_dir_down.hello_world_from_other_dir()

"""
    basically this is in case you need to have things with matching names
    so you don't get confused or have a "namespace collision" in which two
    functions have the same name. it's not a great idea to do unless you
    need to do it. You will notice in each of the things that I am importing
    there is a function called get_money(). they have the same name but do
    different things. because we only imported the "first half" of what we
    need to use them, we can do some easily like this:
"""

# which get_money()? the one from utils
utils.get_money()

# which get_money() the one from OtherUtils.utils_one_dir_down
OtherUtils.utils_one_dir_down.get_money()

"""
    you've probaby seen this in R as 'utils::get_money()', using the C++ style
    imports, but I am going to cover all the bases in this in case we stumble
    onto something illuminating

    Python knows which one we mean because we access their path not just thier
    name. it's like we're usng their full name to specify which person we mean
    if we had use "from x import get_money" there would be two functions in
    the namespace called get_money() and the Python interpreter would not
    know which to use
"""