Splinterlands Api/Bot Learning: 3. How to write a program to realize automatic card (rent multi cards)

image.png
If you don't know how to rent a card through API, please go to my last blog
https://peakd.com/hive-13323/@wohefengyiyang/splinterlands-apibot-learning-2-how-to-write-a-program-to-realize-automatic-card-rental-by-using-python

In my last blog, I explained how to rent a card. So how to rent multi cards?

1. The easiest way is to rent a card many times

cards_sorted_one = get_rent_cards_xp(335, 3, False, 1, 3)
for card_sorted in cards_sorted:
    if verify(card_sorted.market_id, card_sorted.uid, card_sorted.detail_id):
        rent_card(username, [card_sorted.market_id], 1, 'DEC')
        break

cards_sorted_two = get_rent_cards_xp(339, 3, False, 1, 3)
for card_sorted in cards_sorted_two:
    if verify(card_sorted.market_id, card_sorted.uid, card_sorted.detail_id):
        rent_card(username, [card_sorted.market_id], 1, 'DEC')
        break

cards_sorted_three = get_rent_cards_xp(333, 3, False, 1, 3)
for card_sorted in cards_sorted_three:
    if verify(card_sorted.market_id, card_sorted.uid, card_sorted.detail_id):
        rent_card(username, [card_sorted.market_id], 1, 'DEC')
        break

2. Using the for loop

HaHaHa, the way of 1 seems too stupid, so use the loop

# Define a Class an array to save your rental card settings
class RentalSetting:
    card_id = ''
    edition = 3
    gold = False
    xp = 1
    price = 0
    
    def __init__(self, c, e, g, x, p):
        self.card_id = c
        self.edition = e
        self.gold = g
        self.xp = x
        self.price = p

rental_setting = [RentalSetting(333,3,False,1,1),RentalSetting(335,3,True,1,1),RentalSetting(339,3,False,1,1)]

for r_setting in rental_setting:
    cards_sorted = get_rent_cards_xp(r_setting.card_id, r_setting.edition, r_setting.gold, r_setting.xp, r_setting.price)
    for card_sorted in cards_sorted:
        if verify(card_sorted.market_id, card_sorted.uid, card_sorted.detail_id):
            rent_card(username, [card_sorted.market_id], 1, 'DEC')
            break

3. Rent multiple identical cards

What should we do iff we want to rent multiple identical cards?

# Define a Class an array to save your rental card settings and amounts
class RentalSetting:
    card_id = ''
    edition = 3
    gold = False
    xp = 1
    price = 0
    amount = 1
    
    def __init__(self, c, e, g, x, p, a):
        self.card_id = c
        self.edition = e
        self.gold = g
        self.xp = x
        self.price = p
        self.amount = a


rental_setting = [RentalSetting(333,3,False,1,1,3),RentalSetting(335,3,True,1,1,4),RentalSetting(339,3,False,1,1,5)]
for r_setting in rental_setting:
    cards_sorted = get_rent_cards_xp(r_setting.card_id, r_setting.edition, r_setting.gold, r_setting.xp, r_setting.price)
    cards_amount = []
    amount = r_setting.amount
    index = 0
    for card_sorted in cards_sorted:
        index = index + 1
        if verify(card_sorted.market_id, card_sorted.uid, card_sorted.detail_id):
            cards_amount.append(card_sorted.market_id)
            amount = amount - 1
            if amount == 0 or index ==len(cards_sorted):
                if len(cards_amount) > 0:
                    rent_card(username, cards_amount, 1, 'DEC')
                    break

4. All codes: you can copy and test it

import requests
from beem import Hive

API2 = "https://api2.splinterlands.com"

# 👇👇👇👇👇👇👇👇👇👇👇 your username
username = 'username'

# 👇👇👇👇👇👇👇👇👇👇👇 your posting keyword and active keyword
passwords = ['aaa', 'bbb']

hive = Hive(keys=passwords)


class Card:
    market_id = ''
    uid = ''
    detail_id = 0
    price = 0

    def __init__(self, m, u, d, p):
        self.market_id = m
        self.uid = u
        self.detail_id = d
        self.price = p

    def __lt__(self, other):
        return self.price < other.price


# Define a Class an array to save your rental card settings and amounts
class RentalSetting:
    card_id = ''
    edition = 3
    gold = False
    xp = 1
    price = 0
    amount = 1

    def __init__(self, c, e, g, x, p, a):
        self.card_id = c
        self.edition = e
        self.gold = g
        self.xp = x
        self.price = p
        self.amount = a


def get_rent_cards_xp(card_id: int, edition: int, gold: bool, xp: int, price: float) -> list:
    url = API2 + "/market/for_rent_by_card"
    request: dict = {"card_detail_id": card_id,
                     "gold": gold,
                     "edition": edition}
    rent_cards = requests.get(url, params=request).json()
    cards = [card for card in rent_cards if card.get("xp") >= xp and float(card.get("buy_price")) <= price]
    v_cards = []
    for c in cards:
        v_cards.append(Card(c.get('market_id'), c.get('uid'), c.get('card_detail_id'), float(c.get('buy_price'))))
    v_cards.sort()
    return v_cards


def verify(market_id: str, uid: str, card_detail_id: int) -> bool:
    url = API2 + "/market/validateListing"
    request: dict = {"card_detail_id": card_detail_id,
                     "uid": uid,
                     "market_id": market_id}
    return requests.get(url, params=request).json().get('isValid')


def rent_card(player: str, card_ids: list[str], days: int, currency: str):
    data: dict = {"items": card_ids,
                  "currency": currency,
                  "days": days,
                  "app": "splinterlands/0.7.139"}
    hive.custom_json("sm_market_rent", data, required_auths=[player], required_posting_auths=[])
    print(player, 'rent cards success')


rental_setting = [RentalSetting(333, 3, False, 1, 1, 3), RentalSetting(335, 3, True, 1, 1, 4),
                  RentalSetting(339, 3, False, 1, 1, 5)]
for r_setting in rental_setting:
    cards_sorted = get_rent_cards_xp(r_setting.card_id, r_setting.edition, r_setting.gold, r_setting.xp,
                                     r_setting.price)
    cards_amount = []
    amount = r_setting.amount
    index = 0
    for card_sorted in cards_sorted:
        index = index + 1
        if verify(card_sorted.market_id, card_sorted.uid, card_sorted.detail_id):
            cards_amount.append(card_sorted.market_id)
            amount = amount - 1
            if amount == 0 or index == len(cards_sorted):
                if len(cards_amount) > 0:
                    rent_card(username, cards_amount, 1, 'DEC')
                    print(username, 'rent cards', cards_amount)
                    break

Next period notice

Setting a power and BCX(power/dec), and automatic card rental

Share today's luck

image.png

If you have any questions, please leave a message in the comment area


0
0
0.000
12 comments
avatar

The people doing V2K with remote neural monitoring want me to believe this lady @battleaxe is an operator. She is involved deeply with her group and @fyrstikken . Her discord is Battleaxe#1003. I cant prove she is the one directly doing the V2K and RNM. Doing it requires more than one person at the least. It cant be done alone. She cant prove she is not one of the ones doing it. I was drugged in my home covertly, it ended badly. They have tried to kill me and are still trying to kill me. I bet nobody does anything at all. Ask @battleaxe to prove it. I bet she wont. They want me to believe the V2K and RNM in me is being broadcast from her location. And what the fuck is "HOMELAND SECURITY" doing about this shit? I think stumbling over their own dicks maybe? Just like they did and are doing with the Havana Syndrome.

They are reckless and should have shown the proper media what they had before taking me hostage for 5 years.

What would you say while having a gun pointed at your head from an undisclosed location? Have people find it? My hands are tied while they play like children with a gun to my head. Its a terrorist act on American soil while some yawn and say its not real or Im a mental case. Many know its real. This is an ignored detrimental to humanity domestic threat. Ask informed soldiers in the American military what their oath is and tell them about the day you asked me why. Nobody has I guess. Maybe someone told ill informed soldiers they cant protect America from military leaders in control with ill intent. How do we protect locked up soldiers from telling the truth? https://ecency.com/fyrstikken/@fairandbalanced/i-am-the-only-motherfucker-on-the-internet-pointing-to-a-direct-source-for-voice-to-skull-electronic-terrorism

0
0
0.000
avatar

Congratulations @wohefengyiyang! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 50 upvotes.
Your next target is to reach 100 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

Support the HiveBuzz project. Vote for our proposal!
0
0
0.000
avatar

Hi,
Could I have your telegram to discuss more?
As I see your code, its just scan 1 time to find the card with settings (we set above). So, could we add more code to scan several times to find suitable card that meet our settings?
Thanks

0
0
0.000
avatar

On this issue, I will gradually update it in my blog in the future. And I‘m sorry that I don't have telegram.
I will update the code about splinterlands in my blog bit by bit

0
0
0.000
avatar
(Edited)

I got the error log:" Error: HTTPSConnectionPool(host='api.hive.blog', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)')))
Lost connection or internal error on node: https://api.hive.blog (1/100) "
what happened ? And my vpn is from Singapore.

0
0
0.000
avatar

For this problem, there's somethong wrong with your vpn that can't sent a request to hive. you can set codes 'hive = Hive(keys=passwords)' to hive = Hive(keys=passwords, node='https://api.deathwing.me')

0
0
0.000
avatar

In most cases, VPN is not required to use this node

0
0
0.000
avatar

Perfect! This problem has been bothering me for two days,thanks a lot!
but there's a new problem,after changed the node and shutdown VPN, i can't play this game, do you have any suggestions?pls

0
0
0.000
avatar

you can use the card rental bot whether you have VPN or not, so you can restart you vpn that the game and bot will run

0
0
0.000
avatar

Well this would be actually a good contribution to all of us, but there's a problem with this cause it actually rent card 1x at the moment not 3x at the moment. with that problem we may encounter decreasing our RC's until we cant no longer rent a card, I suggest to add a line that could maybe increase also our RC's like transfering dec to someones account so that it could automate, you can check my modified version of this code guys. also thanks to @wohefengyiyang

0
0
0.000
avatar

Well this would be actually a good contribution to all of us, but there's a problem with this cause it actually rent card 1x at the moment not 3x at the moment. with that problem we may encounter decreasing our RC's until we cant no longer rent a card, I suggest to add a line that could maybe increase also our RC's like transfering dec to someones account so that it could automate, you can check my modified version of this code guys https://peakd.com/autorent/@vin-aledo2k/how-to-rent-multiple-cards-in-python . also thanks to @wohefengyiyang

0
0
0.000