Skip to content

Commit

Permalink
Implemented Item delition and webpage updates
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyrzuyev committed Feb 22, 2024
1 parent 28a97b4 commit 012b449
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
27 changes: 27 additions & 0 deletions buff2steam/webgui/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self,app_id, market_hash_name, steam_price, buff_id, buff_price, vo
class Items():
def __init__(self) -> None:
self.list :list[_Item] = []
self.latest_list = self.get_steam_decreasing
self._current_item :_Item = None
self._steam_increasing :list[_Item]= []
self._steam_decreasing :list[_Item]= []
Expand All @@ -40,54 +41,80 @@ def add_item(self, app_id, market_hash_name, steam_price, buff_id, buff_price, v
self._wipe_chached_lists()
return

def delete_item(self, del_item):
for item in self.list:
if item.market_hash_name == del_item:
self.list.remove(item)
logger.debug(f'Removed {del_item} from database list')
self._wipe_chached_lists()
return
logger.debug(f'Item {del_item} not in databse')
return

##Soring data

def get_steam_increasing(self) -> "list[_Item]":
if bool(self._steam_increasing):
self.latest_list = self.get_steam_increasing
return self._steam_increasing
self._steam_increasing = sorted(self.list, key=lambda item: item.steam_price)
self.latest_list = self.get_steam_increasing
return self._steam_increasing

def get_steam_decreasing(self) -> "list[_Item]":
if bool(self._steam_decreasing):
self.latest_list = self.get_steam_decreasing
return self._steam_decreasing
self._steam_decreasing = self.get_steam_increasing()[::-1]
self.latest_list = self.get_steam_decreasing
return self._steam_decreasing

def get_buff_increasing(self) -> "list[_Item]":
if bool(self._buff_increasing):
self.latest_list = self.get_buff_increasing
return self._buff_increasing
self._buff_increasing = sorted(self.list, key= lambda item: item.buff_price)
self.latest_list = self.get_buff_increasing
return self._buff_increasing

def get_buff_decreasing(self) -> "list[_Item]":
if bool(self._buff_decreasing):
self.latest_list = self.get_buff_decreasing
return self._buff_decreasing
self._buff_decreasing = self.get_buff_increasing()[::-1]
self.latest_list = self.get_buff_decreasing
return self._buff_decreasing

def get_volume_increasing(self) -> "list[_Item]":
if bool(self._volume_increasing):
self.latest_list = self.get_volume_increasing
return self._volume_increasing
self._volume_increasing = sorted(self.list, key= lambda item: item.volume)
self.latest_list = self.get_volume_increasing
return self._volume_decreasing

def get_volume_decreasing(self) -> "list[_Item]":
if bool(self._volume_decreasing):
self.latest_list = self.get_volume_decreasing
return self._volume_decreasing
self._volume_decreasing = self.get_volume_increasing()[::-1]
self.latest_list = self.get_volume_decreasing
return self._volume_decreasing

def get_ratio_increasing(self) -> "list[_Item]":
if bool(self._ratio_increasing):
self.latest_list = self.get_ratio_increasing
return self._ratio_increasing
self._ratio_increasing = sorted(self.list, key= lambda item: item.ratio)
self.latest_list = self.get_ratio_increasing
return self._ratio_increasing

def get_ratio_decreasing(self) -> "list[_Item]":
if bool(self._ratio_decreasing):
self.latest_list = self.get_ratio_decreasing
return self._ratio_decreasing
self._ratio_decreasing = self.get_ratio_increasing()[::-1]
self.latest_list = self.get_ratio_decreasing
return self._ratio_decreasing

##Done sorting data
Expand Down
14 changes: 9 additions & 5 deletions buff2steam/webgui/site.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, render_template, Blueprint
from flask import Flask, render_template, Blueprint, request
from buff2steam.webgui.db import items
import threading

Expand All @@ -13,10 +13,6 @@ def start_app():
def index():
return render_template("index.html")

@main.route("/refresh")
def refresh():
return render_template("add_items.html", results=items.list)

#sorting

@main.route("/sort_buff_up")
Expand Down Expand Up @@ -51,7 +47,15 @@ def sort_ratio_up():
def sort_ratio_down():
return render_template("add_items.html", results=items.get_ratio_decreasing())

@main.route("/delete_item")
def delete_item():
item_name = request.args.get("market_hash_name")
items.delete_item(item_name)
return render_template("add_items.html", results=items.latest_list())

@main.route("/refresh")
def events():
return render_template("add_items.html", results=items.latest_list())

flask_thread = threading.Thread(target=start_app)
flask_thread.start()
1 change: 1 addition & 0 deletions buff2steam/webgui/templates/add_items.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<td><a href="{{result.steam_link}}"">{{ result.steam_price }}</a></td>
<td>{{ result.volume }}</td>
<td>{{ result.ratio }}</td>
<td> <button type="button" name="market_hash_name" hx-get="/delete_item?market_hash_name={{ result.market_hash_name }}" hx-target="#result">X</button> </td>
</tr>
{% endfor %}
7 changes: 2 additions & 5 deletions buff2steam/webgui/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
</head>
<section class="section">
<div class="columns">
<div>
<button type="button" hx-get="/refresh" hx-target="#result">Refresh</button>
</div>
</div>
<table class="table is-fullwidth">
<thead>
Expand All @@ -22,10 +19,10 @@
<th>Steam Price<button type="button" hx-get="/sort_steam_up" hx-target="#result"></button><button type="button" hx-get="/sort_steam_down" hx-target="#result"></button></th>
<th>Volume<button type="button" hx-get="/sort_volume_up" hx-target="#result"></button><button type="button" hx-get="/sort_volume_down" hx-target="#result"></button></th>
<th>Ratio<button type="button" hx-get="/sort_ratio_up" hx-target="#result"></button><button type="button" hx-get="/sort_ratio_down" hx-target="#result"></button></th>
<th>Delete</th>
</tr>
</thead>

<tbody id="result">
<tbody id="result" hx-get="/refresh" hx-trigger="every 1s">
</tbody>
</table>
</section>
Expand Down

0 comments on commit 012b449

Please sign in to comment.