trackopy¶
Overview¶
trackopy
is a Python 3 wrapper library for the Track-o-bot API.
It requires the requests
module and Python 3. No, it does not
support Python 2.
Installation¶
pip install trackopy
Usage¶
The library relies on the Trackobot
class. All methods are
documented and easy to use.
import trackopy
# from trackopy import *
# from trackopy import Trackobot
# All of the above are valid
# You can create new users if you do not already have an account
# The returned data will look like {'username': 'foo-bar-1234', 'password': 'abcdefgh'}
user = trackopy.Trackobot.create_user()
trackobot = trackopy.Trackobot(user['username'], user['password'])
# Generate a profile link
url = trackobot.one_time_auth()
# Get your stats by arena, class, or deck
stats = trackobot.stats(stats_type='decks')
stats = trackobot.stats(stats_type='classes')
stats = trackobot.stats(stats_type='arena')
# Get supported deck archetypes
decks = trackobot.decks()
# Reset your account
trackobot.reset()
# Get game history
history = trackobot.history()
arena_history = trackobot.arena_history()
In addition to the above, you can upload games, modify game metadata, delete games, or toggle automatic deck tracking. To learn more about the available functionality, please read the docs.
Please ensure you are using your Trackobot password, not your Trackobot API key. You can get your password from the Trackobot desktop app by exporting your user data to a file. Your password will be the second string in the file with spaces between each character. Remove the spaces and you should have a password of length 8.
CLI¶
Starting with v2.0, there is an included CLI utility for interacting with trackobot.com.
It serves as an example of how to use the library as well as a convenient way of getting data quickly.
Some people may only need simple functionality from this library, and this utility provides that.
It implements all available commands in trackopy
.
It is installed with the library and can be run with the tb
command.
See all arguments and functionality with tb --help
.
License¶
This project is licensed under the MIT license. You can read more in the LICENSE file.
API¶
-
class
trackopy.
Trackobot
(username, password)¶ -
arena_history
(page: int = 1) → dict¶ Get arena game history for the user by page. Returns JSON as a dictionary representing each game.
Parameters: page (int) – The page number Returns: Dictionary of game data Return type: dict Raises: requests.exceptions.HTTPError on error
-
static
create_user
() → dict¶ Create a new username and password in Trackobot. Returns JSON of the format {‘username’: ‘newuser’, ‘password’: ‘password}
Returns: Dictionary of new user data Raises: requests.exceptions.HTTPError on error
-
decks
() → dict¶ Get the deck archetypes supported by Track-o-bot.
Returns: Dictionary listing each archetype by class Return type: dict Raises: requests.exceptions.HTTPError on error
-
delete_game
(game_id: int)¶ Delete the specified game from Trackobot.
Parameters: game_id (int) – The ID of the game to delete Returns: None
-
history
(page: int = 1, query: str = None) → dict¶ Get game history for the user by page. Each page contains 15 games. Returns JSON as a dictionary representing each game. Note that this will include arena matches.
Parameters: - page (int) – The page number
- query (str) – A query string to narrow results
Returns: Dictionary of game data
Return type: dict
Raises: requests.exceptions.HTTPError on error
-
modify_metadata
(game_id: int, param: str, value: str) → bool¶ Modify the metadata of a specified game. Possible parameters that can be changed are: added, mode, win, hero, opponent, coin, duration, rank, legend, deck_id, opponent_deck_id, note. It is up to the user to know the correct possible values for each of these parameters.
Parameters: - game_id (int) – The ID of the game to be modified
- param (str) – The name of the parameter to be modified
- value (str) – The new value for the parameter
Returns: True if successfully changed, False otherwise
Return type: bool
Raises: ValueError
-
one_time_auth
() → str¶ Generate a one-time URL for opening your profile
Returns: Profile URL Return type: str Raises: requests.exceptions.HTTPError on error
-
rename_user
(name: str)¶ Rename your user to something else.
Parameters: name (str) – The new display name Returns: None
-
reset
(modes: list = None)¶ Reset the user’s account data for the specified game modes. Supported modes values are “ranked”, “casual”, “practice”, “arena”, and “friendly”.
Parameters: modes (list) – A list of the modes to reset Returns: None Raises: requests.exceptions.HTTPError on error Raises: ValueError
-
stats
(stats_type: str = 'decks', time_range: str = 'all', mode: str = 'all', start: datetime.datetime = None, end: datetime.datetime = None, as_hero: str = None, vs_hero: str = None, as_deck: int = None, vs_deck: int = None) → dict¶ Get the user’s statistics by deck, class, or for arena. This will return a dictionary with statistics associated with the requested type. You can specify a time range to search under as well as what modes to get stats for.
Parameters: - stats_type (str) – The type of stats you want to see. One of decks, classes, arena
- time_range (str) – A time range to get stats for. One of current_month, all, last_3_days, last_24_hours, custom
- mode (str) – The game mode to get stats for. One of ranked, arena, casual, friendly, all
- start (datetime.datetime) – If using “custom” for time_range, a starting datetime.datetime date
- end (datetime.datetime) – If using “custom” for time_range, an ending datetime.datetime date
- as_hero (str) – If getting by class, only get stats for playing as the specified hero
- vs_hero (str) – If getting by class, only get stats for playing against the specified hero
- as_deck (int) – If getting by deck, only get stats for playing as the specified deck. Get the deck id from a call to decks()
- vs_deck (int) – If getting by deck, only get stats for playing against the specified deck. Get the deck id from a call to decks()
Returns: Dictionary of stats
Return type: dict
Raises: requests.exceptions.HTTPError on error
Raises: ValueError
Raises: TypeError
-
toggle_tracking
(enabled: bool = True)¶ Enable or disable automatic deck tracking
Parameters: enabled (bool) – If True, tracking is enabled, else it is disabled Return None: Raises: requests.exceptions.HTTPError on error
-
upload_game
(game_data: dict) → dict¶ Upload a new game’s data to Trackobot. This method assumes you have properly formatted your game data dictionary. For instructions on how to do so, please follow the guide here: https://gist.github.com/stevschmid/120adcbc5f1f7cb31bc5
Parameters: game_data (dict) – The metadata and card data for the new game Returns: JSON dictionary of the newly created game Return type: dict Raises: requests.exceptions.HTTPError on error
-