Skip to content

Commit

Permalink
v1.2.8
Browse files Browse the repository at this point in the history
v1.2.8
  • Loading branch information
offish authored May 31, 2021
2 parents 3a23f23 + 1f1da3a commit c19eb37
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 74 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Automated trading bot for Team Fortress 2 using prices provided by [Prices.TF](h
Backpack.tf listing might be added in the future.

## Screenshots
![GUI](https://user-images.githubusercontent.com/30203217/99878974-6eca1f80-2c09-11eb-83e1-07514a5d694f.png)
![GUI](https://user-images.githubusercontent.com/30203217/120229592-c2b76000-c24d-11eb-8d23-725556925ba3.png)
![Screenshot](https://user-images.githubusercontent.com/30203217/99878862-a2587a00-2c08-11eb-9211-8c8ac86821e6.png)

## Installation
Expand Down Expand Up @@ -75,9 +75,6 @@ decline_trade_hold = True
decline_scam_offers = True
allow_craft_hats = True
save_trades = True

craft_hat_buy = 1.55
craft_hat_sell = 1.66
```


Expand Down
2 changes: 1 addition & 1 deletion express/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__title__ = "tf2-express"
__author__ = "offish"
__license__ = "MIT"
__version__ = "1.2.7"
__version__ = "1.2.8"
10 changes: 6 additions & 4 deletions express/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ def _get_price(name: str) -> dict:
return prices.find_one({"name": name})


def _get_pricelist() -> dict:
def get_database_pricelist() -> dict:
return prices.find()


def add_price(name: str) -> None:
prices.insert({"name": name, "buy": None, "sell": None})
prices.insert({"name": name, "autoprice": True, "buy": None, "sell": None})
log.info(f"Added {name} to the database")


def update_price(name: str, buy: dict, sell: dict) -> None:
prices.replace_one({"name": name}, {"name": name, "buy": buy, "sell": sell})
def update_price(name: str, autoprice: bool, buy: dict, sell: dict) -> None:
prices.replace_one(
{"name": name}, {"name": name, "autoprice": autoprice, "buy": buy, "sell": sell}
)
log.info(f"Updated price for {name}")


Expand Down
2 changes: 1 addition & 1 deletion express/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def valuate(items: dict, intent: str, item_list: list) -> int:
total = 0
high = float(10 ** 5)
high = float(10 ** 10)

for i in items:
item = Item(items[i])
Expand Down
14 changes: 6 additions & 8 deletions express/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .methods import request
from .logging import Log
from .utils import to_scrap, to_refined
from .settings import craft_hat_buy, craft_hat_sell


log = Log()

Expand All @@ -18,9 +18,6 @@ def get_pricelist() -> dict:


def get_price(name: str, intent: str) -> float:
if name == "Random Craft Hat":
return craft_hat_sell if intent == "sell" else craft_hat_buy

price = _get_price(name)[intent]
metal = to_scrap(price["metal"])
keys = price.get("keys")
Expand All @@ -44,11 +41,12 @@ def update_pricelist(items: list) -> None:
if name in items:
item = get_item(name)

if not (item["buy"] or item["sell"]):
update_price(name, i["buy"], i["sell"])
if item.get("autoprice"):
if not (item["buy"] or item["sell"]):
update_price(name, True, i["buy"], i["sell"])

elif not (i["buy"] == item["buy"]) or not (i["sell"] == item["sell"]):
update_price(name, i["buy"], i["sell"])
elif not (i["buy"] == item["buy"]) or not (i["sell"] == item["sell"]):
update_price(name, True, i["buy"], i["sell"])

# Does not warn the user if an item in the database
# can't be found in Prices.TF's pricelist
3 changes: 0 additions & 3 deletions express/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
decline_scam_offers = True
allow_craft_hats = True
save_trades = True

craft_hat_buy = 1.44
craft_hat_sell = 1.55
60 changes: 55 additions & 5 deletions express/ui/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

from flask import Flask, render_template, request, redirect, abort

from .. import database

from ..database import *
from ..prices import get_pricelist


import json


app = Flask(__name__)
Expand All @@ -15,17 +20,61 @@ def overview():

@app.route("/trades")
def trades():
return render_template("trades.html", trades=database.get_trades())
return render_template("trades.html", trades=get_trades())


@app.route("/prices")
def prices():
return render_template("prices.html", items=database._get_pricelist())
return render_template("prices.html", items=get_database_pricelist())


@app.route("/pricelist")
def pricelist():
with open("./express/ui/pricelist.json", "w") as f:
json.dump(get_pricelist(), f)
return redirect("/prices")


@app.route("/price/<name>")
def price(name):
try:
pricelist = json.loads(open("./express/ui/pricelist.json", "r").read())
item = {}

for i in pricelist["items"]:
if name == i["name"]:
item = i

if not (item.get("buy") and item["sell"]):
return redirect("/prices")

update_price(name, True, item["buy"], item["sell"])
return redirect("/prices")

except FileNotFoundError:
return redirect("/pricelist")


@app.route("/delete/<name>")
def delete(name):
database.remove_price(name)
remove_price(name)
return redirect("/prices")


@app.route("/edit", methods=["POST"])
def edit():
data = dict(request.form.items())

print(data)

name, buy, sell = (
data["name"],
{"keys": int(data["buy_keys"]), "metal": float(data["buy_metal"])},
{"keys": int(data["sell_keys"]), "metal": float(data["sell_metal"])},
)

update_price(name, False, buy, sell)

return redirect("/prices")


Expand All @@ -34,7 +83,8 @@ def add():
data = dict(request.form.items())
names = data["names"].split(", ")
for name in names:
database.add_price(name)
if not name in get_items():
add_price(name)
return redirect("/prices")


Expand Down
118 changes: 71 additions & 47 deletions express/ui/templates/prices.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
<title>prices - tf2-express</title>
</head>

<body>
<div class="container">
<h1>PRICES</h1>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>prices - tf2-express</title>
</head>

<p>Add multiple items separted by comma(s)</p>
<form action="/add" method="POST" class="my-4 form-inline">
<label for="names" class="sr-only">Item name</label>
<input required placeholder="The Team Captain, Non-Craftable Tour of Duty Ticket" type="text" name="names" id="names" class="form-control col mr-2"></th>
<button class="btn btn-success" type="submit">Add</button>
</form>
<p>Item prices will be added and updated when running <i>main.py</i>.</p>
<p>If the bot does not add its prices on startup you might have written in the wrong
<body class="bg-dark text-white">
<div class="container">
<h1 style="margin-top: 5%;">PRICES</h1>

<p>Add multiple items by using commas</p>
<form action="/add" method="POST" class="my-4 form-inline">
<label for="names" class="sr-only">Item name</label>
<input required placeholder="The Team Captain, Non-Craftable Tour of Duty Ticket" type="text" name="names"
id="names" class="form-control col mr-2"></th>
<button class="btn btn-success" type="submit">Add</button>
</form>
<p>Item prices will be added and updated when running <i>main.py</i>.</p>
<p>If the bot does not add its prices on startup you might have written in the wrong
item name. E.g. "Team Captain" instead of "The Team Captain".</p>
<table class="table table-hover">
<thead>
<tr>
<th>Item name</th>
<th>Buy keys</th>
<th>Buy refined</th>
<th>Sell keys</th>
<th>Sell refined</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<th>{{ item["name"] }}</th>
<th>{{ item["buy"]["keys"] }}</th>
<th>{{ item["buy"]["metal"] }}</th>
<th>{{ item["sell"]["keys"] }}</th>
<th>{{ item["sell"]["metal"] }}</th>
<th><a href="/delete/{{ item["name"] }}"><button type="button" class="btn btn-danger">Delete</button></a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
<p style="float: left;">Update pricelist to get all items and newer prices.</p>
<a style="float: right; margin-bottom: 20px;" href="/pricelist"><button class="btn btn-success">Update
pricelist</button></a>
<table class="table table-dark table-hover">
<thead>
<tr>
<th>Item name</th>
<th>Autoprice</th>
<th>Buy keys</th>
<th>Buy refined</th>
<th>Sell keys</th>
<th>Sell refined</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<form action="/edit" method="POST">
<input name="name" id="name" style="display: none;" value="{{ item['name'] }}" type="text">
<th>{{ item['name'] }}
</th>
<th>{{ item["autoprice"] }}</th>
<th><input name="buy_keys" id="buy_keys" style="width: 50px;" value="{{ item['buy']['keys'] }}"
min="0" type="number" step="any">
</th>
<th><input name="buy_metal" id="buy_metal" style="width: 70px;"
value="{{ item['buy']['metal'] }}" min="0" type="number" step="any">
</th>
<th><input name="sell_keys" id="sell_keys" style="width: 50px;"
value="{{ item['sell']['keys'] }}" min="0" type="number" step="any">
</th>
<th><input name="sell_metal" id="sell_metal" style="width: 70px;"
value="{{ item['sell']['metal'] }}" min="0" type="number" step="any">
</th>

<th>
<button type="submit" class="btn btn-success">Save</button>
<a href="/price/{{ item['name'] }}"><button type="button"
class="btn btn-warning">Price</button></a>
<a href="/delete/{{ item['name'] }}"><button type="button"
class="btn btn-danger">Delete</button></a></td>
</tr>
</form>
{% endfor %}
</tbody>
</table>
</div>
</body>

</html>
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def run(bot: dict) -> None:

except KeyboardInterrupt:
client.logout()
log.error(f"Stopping")
log.info(f"Stopping")


def database() -> None:
Expand Down

0 comments on commit c19eb37

Please sign in to comment.