Рассчитать размер и размер прибыли в python flask - PullRequest
0 голосов
/ 27 мая 2020

Хорошо, поэтому я пытаюсь подсчитать прибыль, которую пользователь может получить в зависимости от того, что они вводят, вот небольшая картина того, как это выглядит: Picture

Теперь то, что я хочу, это

  1. Рассчитать разницу между ценой продажи и покупки
  2. Посмотрите, сколько пользователь может купить, например, 100 тысяч монет (каждый элемент)
  3. Отображение прибыли, которую пользователь может получить от каждого продукта, в зависимости от их ввода

Я пытался атаковать эти 2 или 3 дня go, не повезло! Тем не менее, удалось получить рабочий сценарий (хотя цены на предметы были сохранены в массивах):

userInput = int(input("How much coins do you want to spend?: "))



for x in range(len(buyPrice)):
    while total+ float(buyPrice[x]) < userInput:
         total += float(buyPrice[x])
         amount += 1
    print("Total Cost: " + str("{:.1f}".format(total)))
    print("Buy: " + str(amount))
    k = float(buyPrice[x])- float(sellPrice[x])
    print("Profit: " + str(k))
    print("----------")
    amount= 0
    total=0
    k=0

Теперь я знаю, что мне нужно выполнить этот «расчет» в Python, но я совершенно не понимаю с чего начать. Я получил "ввод" для работы, я могу сохранить ввод пользователя и распечатать его в таблице.

Вот app.route для этой страницы:

@app.route('/bflipper', methods=['POST', 'GET'])
def bFlipper():
    f = requests.get(
        'https://api.hypixel.net/skyblock/bazaar?key=[have to keep secret, can share IF NEEDED]').json()
    products = [
        {
            "sell_price": product["sell_summary"][:1],
            "buy_price": product["buy_summary"][:1]
        }
        for product in f["products"].values()
    ]
    sellPrice = products[0]["sell_price"]
    print(sellPrice)
    if request.method == 'POST':
        userInput = request.form['coins']
        return render_template("flipper.html", userInput=userInput, products=products)
    else:
        return render_template("flipper.html", products=products)

И если вам нужен мой HTML, вот он:

<div class="container">
  <div class="search_div">
    <form method="POST">
      <input class="search-box" type="text" name="coins" />
      <input type="submit" class="search-btn" />
    </form>
  </div>

  <table
    id="myTable"
    class="table table-striped table-bordered table-sm table-dark"
    cellspacing="0"
  >
    <thead>
      <tr>
        <th aria-label="Product Name" data-balloon-pos="up">Product</th>
        <th aria-label="How much you will earn" data-balloon-pos="up">
          Profit
        </th>
        <th aria-label="How many you should buy" data-balloon-pos="up">
          Amount
        </th>
        <th aria-label="How much you should buy for" data-balloon-pos="up">
          Sell For
        </th>
        <th aria-label="How much you should sell for" data-balloon-pos="up">
          Buy for
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        {% for product in products %}{% for buy in product.buy_price %}{% for
        sell in product.sell_price %}
      </tr>

      <tr>
        <td>{{ product.id|replace("_", ' ')|lower()|title() }}</td>
        <td>{{ userInput }}</td>
        <td>temp</td>
        <td>{{ buy.pricePerUnit }}</td>
        <td>{{ sell.pricePerUnit }}</td>
        {% endfor %} {% endfor %} {% endfor %}
      </tr>
    </tbody>
  </table>
</div>

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...