No project description provided
Project description
py_tf2_currency
A Python library for handling Team Fortress 2 currency calculations with support for keys and metal.
Overview
This library provides a robust way to handle Team Fortress 2's virtual currency system, which consists of keys and metal. It allows for precise calculations, conversions, and comparisons between different currency amounts.
Do note that this library is still in the testing phase and will require tweaks to improve accuracy and stability. Please feel free to raise issues or contribute to the project to help improve its functionality.
Features
- Create currency objects with keys and metal values
- Convert between different currency formats (keys, metal, scrap)
- Perform arithmetic operations (add, remove) on currency values
- Compare currency values (equal, bigger, smaller)
- Handle currency conversions with proper rounding
- Proper string representation of currency values
Installation
pip install py_tf2_currency
Basic Usage
from py_tf2_currency import Currency
# Create a currency object
currency = Currency({"keys": 2, "metal": 3.55})
# Display the currency
print(currency) # Output: 2 keys, 3.55 metal
# Check if currency is empty
is_empty = currency.is_empty()
print(is_empty) # False
# Convert to dictionary
currency_dict = currency.to_dict()
print(currency_dict) # {"keys": 2, "metal": 3.55}
Currency Conversions
from py_tf2_currency import Currency
# Assuming 1 key = 60 refined metal (conversion rate)
conversion_rate = 60
# Convert from scrap to currency
scrap_amount = 550 # scrap
currency = Currency.from_scrap(scrap_amount, conversion_rate)
print(currency) # 1 key 1.11 metal
# Convert from keys to currency
keys_amount = 2.5 # keys
currency = Currency.from_keys(keys_amount, conversion_rate)
print(currency) # 2 keys, 30.0 metal
# Convert currency to scrap
scrap_value = currency.to_scrap(conversion_rate)
print(scrap_value) # 1350 scrap
# Convert currency to keys
keys_value = currency.to_keys(conversion_rate)
print(keys_value) # 2.5 'keys'
Currency Operations
from py_tf2_currency import Currency
# Create a currency object
currency = Currency({"keys": 1, "metal": 5})
# Add operations
currency.add_keys(2, 60) # Add 2 keys (conversion rate: 60 ref)
currency.add_metal(
3.33, 60
) # Add 3.33 refined metal (conversion rate needed when keys are present)
currency.add_scrap(9, 60) # Add 9 scrap (conversion rate needed when keys are present)
# Remove operations
currency.remove_keys(1, 60) # Remove 1 key
currency.remove_metal(
2, 60
) # Remove 2 refined metal (conversion rate needed when keys are present)
# Add/remove another currency object
other_currency = {"keys": 0, "metal": 10}
currency.add_currency(other_currency, 60)
currency.remove_currency({"keys": 0, "metal": 5}, 60)
Currency Comparisons
from py_tf2_currency import Currency
currency_a = Currency({"keys": 1, "metal": 10})
currency_b = Currency({"keys": 1, "metal": 5})
# Compare currencies
is_equal = currency_a.is_equal(currency_b) # False
is_bigger = currency_a.is_bigger(currency_b) # True
is_smaller = currency_a.is_smaller(currency_b) # False
Error Handling
The library includes a custom CurrencyError exception for handling currency-related errors:
from py_tf2_currency import Currency, CurrencyError
try:
# Attempting to convert keys to scrap without a conversion rate
currency = Currency({"keys": 1, "metal": 0})
scrap_value = currency.to_scrap() # Will raise CurrencyError
except CurrencyError as e:
print(f"Error: {e.message}") # "Conversion value is required when keys are present."
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_tf2_currency-0.2.0.tar.gz.
File metadata
- Download URL: py_tf2_currency-0.2.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
899388787b8358c5d174ff16cd0183e0cfcff88cb64f0c3c19d4902c356c3440
|
|
| MD5 |
e7149d4d68c5b7568f74e551e94bffc1
|
|
| BLAKE2b-256 |
9699ec746a06fb71d32ed624a4c49e7d7f697602516663692f5be58d46b19c64
|
File details
Details for the file py_tf2_currency-0.2.0-py3-none-any.whl.
File metadata
- Download URL: py_tf2_currency-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91aefc825418c67033024bef3ec07116c5e14395940a749e927e3ed5c767bae7
|
|
| MD5 |
44a7874cdae8c686dc14953588879290
|
|
| BLAKE2b-256 |
100e7a7141da0987db0890e4d949908fe20f294b655d8b0bb1c4f9f0b11ce5f9
|