I have spent quite a bit of time working with Splintelands data over the last years. This has included mining battle data, analyzing card stats, guild data etc. Something I have long been thinking about is to compile these various scripts, functions and classes into a python package, in case someone else could have use for it.
I finally pulled the trigger and created a Github repository for it. I named it spltools, because I am not particularly creative with these things. Anyway, the link to the repo is:
https://github.com/Kalkulus2/spltools
For now, it only contains two things.
- A function to download Splinterlands card information
- A guild class
I plan to slowly add in new functionality to this package over time. Updates will likely be accompanied by a Hive post.
Downloading card details: getCardData()
The main content of the package currently is the getCardData function, which downloads information about all Splinterlands cards from https://api2.splinterlands.com/cards/get_details. (Some browsers, like Firefox, allow you to view the data in that url conveniently in the browser).
The function is very simple. There is no input argument, and all it does is to ask splinterlands for the card information data, and then use the json library to build a python dictionary from the returned data. If the data request is successful, we get the card information in the carddata variable.
I then add an id filter with a list comprehension, to remove all the Soulkeep cards from the data. The Soulkeep cards have ids larger than 10000, while Splinterlands cards currently go up to 706.
Here we have the name, id, color etc. The stats field is another dictionary with keys "attack", "ranged", etc, which are lists containing the card stats at each level.
We also get information about the card distribution. Goblin Shaman has 185254 total printed.
Example usage
I have a goal with this package to provide examples for most of the functions and classes it contains. To start with, I have made this tiny program to call the getCardData function. This script, printAllNamesAndIds.py, can be found in the examples folder:
This program imports the getCardData function, calls it, and then loops over the cards and prints their names and ids. I am a big fan of the fstring functionality in Python, which allows me to easily insert the names and ids into the output string . The output looks like this:
Final words
If you have not yet joined Splinterlands please click the referral link below to get started.
Join Splinterlands
Best wishes
@Kalkulus
Congratulations @kalkulus! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 22000 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out our last posts:
Thanks for sharing! - @rehan12
👍
!BEER
!BBH
!WINE
View or trade
BEER
.Hey @kalkulus, here is a little bit of
BEER
from @eii for you. Enjoy it!Learn how to earn FREE BEER each day by staking your
BEER
.@kalkulus! @eii likes your content! so I just sent 1 BBH to your account on behalf of @eii. (2/5)
(html comment removed: )