|
1 | | -# tf2-utils |
2 | | - |
3 | | -``` |
4 | | -pip install tf2utils |
5 | | -``` |
| 1 | +# tf2-utils |
| 2 | +[](https://github.com/offish/tf2-utils/blob/master/LICENSE) |
| 3 | +[](https://github.com/offish/tf2-utils/stargazers) |
| 4 | +[](https://github.com/offish/tf2-utils/issues) |
| 5 | +[](https://github.com/offish/tf2-utils) |
| 6 | +[](https://discord.gg/t8nHSvA) |
| 7 | +[](https://github.com/psf/black) |
| 8 | + |
| 9 | +Tools and utilities for TF2 trading. Use 3rd party inventory providers, get SKUs directly from inventories, listen to BackpackTF's websocket and more. |
| 10 | + |
| 11 | +## Donate |
| 12 | +- BTC: `bc1qntlxs7v76j0zpgkwm62f6z0spsvyezhcmsp0z2` |
| 13 | +- [Steam Trade Offer](https://steamcommunity.com/tradeoffer/new/?partner=293059984&token=0-l_idZR) |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +### Inventory fetching |
| 18 | +```python |
| 19 | +from tf2_utils import Inventory |
| 20 | + |
| 21 | +# using 3rd party provider to avoid being rate-limited |
| 22 | +provider = Inventory("steamsupply", "9st947vs0qmgfpeqde1gj92l0oqmhysm") |
| 23 | + |
| 24 | +# using steam as inventory provider |
| 25 | +provider = Inventory() # or Inventory("steamcommunity") |
| 26 | + |
| 27 | +# get an inventory |
| 28 | +inventory = provider.fetch("76561198253325712") |
| 29 | +``` |
| 30 | + |
| 31 | +### Gettings SKUs from inventories |
| 32 | +**NOTE: NOT ALL SKU ATTRIBUTES ARE ADDED YET** |
| 33 | +#### Get SKUs implicitly |
| 34 | +```python |
| 35 | +from tf2_utils import Inventory, map_inventory |
| 36 | + |
| 37 | +provider = Inventory("steamcommunity") |
| 38 | + |
| 39 | +user_inventory = provider.fetch("76561198253325712") |
| 40 | +inventory = map_inventory(user_inventory, add_skus=True) |
| 41 | +``` |
| 42 | + |
| 43 | +#### Get a particular item's SKU |
| 44 | +```python |
| 45 | +from tf2_utils import get_sku |
| 46 | + |
| 47 | +inventory = map_inventory(user_inventory) |
| 48 | + |
| 49 | +for item in inventory: |
| 50 | + sku = get_sku(item) |
| 51 | +``` |
| 52 | + |
| 53 | +### BackpackTF Websocket |
| 54 | +#### Handle one listing at a time |
| 55 | +```python |
| 56 | +from tf2_utils import BackpackTFWebsocket |
| 57 | + |
| 58 | +def my_function(data: dict): |
| 59 | + print("got data!", data) |
| 60 | + |
| 61 | +socket = BackpackTFWebsocket(my_function) |
| 62 | + |
| 63 | +socket.listen() |
| 64 | +``` |
| 65 | + |
| 66 | +#### Handle list of listings at a time |
| 67 | +```python |
| 68 | +from tf2_utils import BackpackTFWebsocket |
| 69 | + |
| 70 | +def my_function(data: list[dict]): |
| 71 | + print("got listings") |
| 72 | + |
| 73 | + for listing in data: |
| 74 | + print("listing", listing) |
| 75 | + |
| 76 | +socket = BackpackTFWebsocket(my_function, solo_entries=False) |
| 77 | + |
| 78 | +socket.listen() |
| 79 | +``` |
| 80 | + |
| 81 | +## Setup |
| 82 | +### Install |
| 83 | +```bash |
| 84 | +pip install tf2-utils |
| 85 | +# or |
| 86 | +python -m pip install tf2-utils |
| 87 | +``` |
| 88 | + |
| 89 | +### Upgrade |
| 90 | +```bash |
| 91 | +pip upgrade tf2-utils |
| 92 | +# or |
| 93 | +python -m pip upgrade tf2-utils |
| 94 | +``` |
| 95 | + |
0 commit comments