Skip to content

Commit 05f0ac2

Browse files
committed
move backpacktf to own package
1 parent 473f381 commit 05f0ac2

File tree

11 files changed

+5
-396
lines changed

11 files changed

+5
-396
lines changed

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Table of Contents
77
:maxdepth: 2
88

99

10-
pages/backpack_tf
1110
pages/currency
1211
pages/inventory
1312
pages/item

docs/pages/backpack_tf.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/pages/sockets.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
Sockets
22
=======
33

4-
BackpackTF Example
5-
------------------
6-
7-
.. literalinclude:: ../usage/backpack_tf_socket.py
8-
:language: python3
9-
104
PricesTF Example
115
----------------
126

docs/usage/backpack_tf.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/usage/backpack_tf_socket.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/usage/prices_tf_socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tf2_utils import PricesTFSocket
1+
from tf2_utils import PricesTFWebsocket
22

33

44
def my_function(data: dict):
@@ -10,7 +10,7 @@ def my_function(data: dict):
1010
# etc. your logic goes here
1111

1212

13-
socket = PricesTFSocket(my_function)
13+
socket = PricesTFWebsocket(my_function)
1414

1515
socket.listen()
1616

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ classifiers = [
1616
"License :: OSI Approved :: MIT License",
1717
"Operating System :: OS Independent",
1818
]
19-
dependencies = ["tf2-sku", "tf2-data", "requests", "websocket-client"]
19+
dependencies = ["tf2-sku", "tf2-data", "backpack-tf", "requests", "websocket-client"]
2020
dynamic = ["version"]
2121

2222
[project.urls]

src/tf2_utils/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
from .offer import Offer
1010
from .utils import *
1111
from .schema import SchemaItemsUtils
12-
from .sockets import BackpackTFSocket, PricesTFSocket
12+
from .sockets import PricesTFWebsocket
1313
from .prices_tf import *
1414
from .inventory import Inventory, map_inventory
1515
from .currency import CurrencyExchange
1616
from .marketplace_tf import *
17-
from .backpack_tf import *

src/tf2_utils/backpack_tf.py

Lines changed: 0 additions & 203 deletions
This file was deleted.

src/tf2_utils/sockets.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,7 @@
66
from .prices_tf import PricesTF
77

88

9-
class BackpackTFSocket:
10-
URL = "wss://ws.backpack.tf/events"
11-
12-
def __init__(
13-
self,
14-
callback: Callable[[dict | list[dict]], None],
15-
solo_entries: bool = True,
16-
headers: dict = {"batch-test": True},
17-
max_size: int | None = None,
18-
settings: dict = {},
19-
) -> None:
20-
"""
21-
Args:
22-
callback: Function pointer where you want the data to end up
23-
solo_entries: If data to callback should be solo entries or a batched list
24-
headers: Additional headers to send to the socket
25-
settings: Additional websocket settings as a dict to be unpacked
26-
"""
27-
self.callback = callback
28-
self.solo_entries = solo_entries
29-
self.headers = headers
30-
self.max_size = max_size
31-
self.settings = settings
32-
33-
def process_messages(self, data: str) -> None:
34-
messages = json.loads(data)
35-
36-
if not self.solo_entries:
37-
self.callback(messages)
38-
return
39-
40-
for message in messages:
41-
payload = message["payload"]
42-
self.callback(payload)
43-
44-
def listen(self) -> None:
45-
"""Listen for messages from BackpackTF"""
46-
with connect(
47-
self.URL,
48-
additional_headers=self.headers,
49-
max_size=self.max_size,
50-
**self.settings,
51-
) as websocket:
52-
while True:
53-
data = websocket.recv()
54-
self.process_messages(data)
55-
56-
57-
class PricesTFSocket:
9+
class PricesTFWebsocket:
5810
URL = "wss://ws.prices.tf"
5911

6012
def __init__(

0 commit comments

Comments
 (0)