好吧,所以我试图根据用户的输入来计算用户可以赚取的利润,下面是有关它的外观的示意图:
现在我要做的是
我在2或3天前曾尝试攻击过,没有运气!虽然设法获得了有效的脚本(尽管商品价格存储在数组中):
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('/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>
谢谢