First commit to spltools, a python package for working with Splinterlands data.

in Splinterlands2 months ago

Image created with Bing image generator

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.

separator.png

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).

image.png

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.


The data returned from this api endpoint is a list of cards, where each card is a dictionary with a number of data fields. For example, the first card in the list is the Goblin Shaman, and the card info looks like this ---->

 

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.

separator.png

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:


image.png

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:


image.png

separator.png

Final words

If you have not yet joined Splinterlands please click the referral link below to get started.


Join Splinterlands

Best wishes
@Kalkulus

separator.png

Sort:  
Loading...

This post has been supported by @Splinterboost with a 15% upvote! Delagate HP to Splinterboost to Earn Daily HIVE rewards for supporting the @Splinterlands community!

Delegate HP | Join Discord

Congratulations @kalkulus! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 21000 upvotes.
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:

Our Hive Power Delegations to the September PUM Winners
Feedback from the October Hive Power Up Day
Hive Power Up Month Challenge - September 2024 Winners List

Thanks for sharing! - @rehan12

👍

!BEER
!BBH
!WINE


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: )