-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
300 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Upload Python Package | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
pypi: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- run: python3 -m pip install --upgrade build && python3 -m build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vscode | ||
__pycache__ | ||
tests/config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# stntrading | ||
[](https://github.com/offish/stntrading/blob/master/LICENSE) | ||
[](https://github.com/offish/stntrading/stargazers) | ||
[](https://github.com/offish/stntrading/issues) | ||
[](https://github.com/offish/stntrading) | ||
[](https://discord.gg/t8nHSvA) | ||
[](https://github.com/psf/black) | ||
|
||
Interact with STNTrading.eu's API hosted at https://api.stntrading.eu | ||
|
||
For getting inventories and item names, I recommend using [tf2-utils](https://github.com/offish/tf2-utils). | ||
|
||
|
||
## Installation | ||
```bash | ||
pip install stntrading | ||
``` | ||
|
||
### Update | ||
```bash | ||
pip install --upgrade stntrading | ||
``` | ||
|
||
# Setup | ||
Find or register your API key on https://stntrading.eu/dev/apikey | ||
|
||
If you want to access BETA endpoints shown [here](https://github.com/STNTrading/public-api/wiki), you need STN Premium. | ||
For more information read [this](https://api.stntrading.eu/docs/#/beta). | ||
|
||
|
||
# Usage | ||
```python | ||
>>> from stntrading import STN, EStateCodes | ||
|
||
>>> stn = STN("26bf8abb59e86b4301aaff5b88547aaf") # (fake api key) | ||
|
||
>>> stn.get_key_prices() | ||
{'success': 1, 'result': {'pricing': {'buyPrice': 570.0, 'sellPrice': 606.0}}} | ||
|
||
>>> stn.get_key_stock() | ||
{'success': 1, 'result': {'stock': {'canBuy': 15, 'canSell': 15, 'stockLevel': 702, 'stockLimit': 1770}}} | ||
|
||
>>> stn.request_key_trade("buy", 1) | ||
{'success': 0, 'error': "Failed to create trade: 'NotEnoughCurrenciesUser'"} | ||
|
||
>>> stn.get_trade_status(20530029) | ||
{'success': 1, 'result': {'trade': {'state': 15, 'tradeOfferId': 6697968536}}} | ||
|
||
>>> EStateCodes(15).name | ||
CANCELLED_AFTER_SENDING | ||
|
||
>>> stn.request_item_trade("buy", "The Team Captain", 1) | ||
{'success': 1, 'result': {'tradeDetails': {'id': 20530029, 'bot': '76561198309976634'}}} | ||
|
||
>>> stn.request_item_trade("sell", [12552033523], 1) | ||
{'success': 0, 'error': "Failed to create trade: 'UserItemOverstocked'"} | ||
|
||
# ---------------------- | ||
# if STN Premium access: | ||
# ---------------------- | ||
>>> stn.get_schema() | ||
{'success': 1, 'result': {'schema': ['A Brush with Death', 'A Color Similar to Slate', 'A Deep Commitment to Purple', ...]}} | ||
|
||
>>> stn.get_item_details("The Team Captain") | ||
{'success': 1, 'item': {'full_name': 'The Team Captain', 'pricing': {'buy': {'keys': 0, 'metal': 10.0}, 'sell': {'keys': 0, 'metal': 10.88}}, 'stock': {'level': 48, 'limit': 100}}} | ||
``` | ||
|
||
|
||
# Documentation | ||
Documentation can be found on the [official wiki](https://github.com/STNTrading/public-api/wiki) or using [Swagger](https://api.stntrading.eu/docs/). | ||
|
||
|
||
# License | ||
Copyright (c) 2020-2024 offish | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the 'Software'), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[build-system] | ||
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "stntrading" | ||
authors = [ | ||
{ name="offish", email="[email protected]" }, | ||
] | ||
description = "Interact with STNTrading's API" | ||
readme = "README.md" | ||
requires-python = ">=3.10" | ||
keywords = ["tf2", "stntrading", "stn"] | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
dependencies = ["requests"] | ||
dynamic = ["version"] | ||
|
||
[project.urls] | ||
"Homepage" = "https://github.com/offish/stntrading" | ||
"Bug Tracker" = "https://github.com/offish/stntrading/issues" | ||
|
||
[tool.setuptools_scm] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,3 @@ | ||
from setuptools import setup, find_packages | ||
import re | ||
|
||
|
||
with open('README.rst', 'r') as f: | ||
long_description = f.read() | ||
|
||
|
||
with open('stntrading/__init__.py') as f: | ||
version = re.search( | ||
r"^__version__\s*=\s*['']([^\'']*)['']", f.read(), re.MULTILINE).group(1) | ||
|
||
|
||
setup( | ||
name='stntrading', | ||
version=version, | ||
author='offish', | ||
author_email='[email protected]', | ||
description='Easily interact with STNTrading\'s public API.', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
license='MIT', | ||
url='https://github.com/offish/py-stntrading', | ||
download_url='https://github.com/offish/py-stntrading/tarball/v' + version, | ||
packages=['stntrading'], | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
], | ||
install_requires=['requests'], | ||
python_requires='>=3.6', | ||
) | ||
from setuptools import setup | ||
|
||
setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
__title__ = "stntrading" | ||
__author__ = "offish" | ||
__license__ = "MIT" | ||
__version__ = "1.1.0" | ||
|
||
|
||
from .enums import EStateCodes | ||
from .exceptions import * | ||
from .stn import STN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import enum | ||
|
||
|
||
class EStatusCodes(enum.IntEnum): | ||
class EStateCodes(enum.IntEnum): | ||
READY_TO_BE_SENT = 0 | ||
SENT = 1 | ||
COMPLETED = 2 | ||
CONFIRM_PENDING = 3 | ||
CANCELLED_AFTER_SENDING = 15 | ||
SENDING_FAILED = 20 | ||
SENDING_FAILED = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class STNTradingException(Exception): | ||
"""General exception""" | ||
|
||
|
||
class NoPremiumAccess(STNTradingException): | ||
""" | ||
Raised if user is trying to access a beta endpoint while not having premium access | ||
""" | ||
|
||
|
||
class InvalidIntent(STNTradingException): | ||
"""Raised if intent is invalid""" |
Oops, something went wrong.