Words
99
Reading
1 min
Listen
Play
2y
Hi @kalkulus,
Nice tool also a big fan of python 😍.
question why do you use the
with urllib.request.urlopen("https://api2.splinterlands.com/cards/get_details") as request:
I like to use this strucure:
base_url = 'https://api2.splinterlands.com/'
land_url = 'https://vapi.splinterlands.com/'
prices_url = 'https://prices.splinterlands.com/'
retry_strategy = LogRetry(
total=10,
status_forcelist=[429, 500, 502, 503, 504],
backoff_factor=2, # wait will be [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
allowed_methods=['HEAD', 'GET', 'OPTIONS']
)
adapter = HTTPAdapter(max_retries=retry_strategy)
http = requests.Session()
http.mount('https://', adapter)
def get_card_details():
address = base_url + 'cards/get_details'
return pd.DataFrame(http.get(address).json()).set_index('id')
Not sure why one is better than the other.
Some feedback:
For Python, the PEP 8 style guide recommends using snake_case for function and variable names.
I would recommend using a base_url to abstract the url.
Might consider a Retry mechanism when users are overloading the spl API. Not sure if it needs in this code or the caller?
Keep up the great work 💪
Here is my spl api i use for my statistics tool.
https://github.com/gamerbeaker007/splinterlands-statistics/blob/main/src/api/spl.py
RE: First commit to spltools, a python package for working with Splinterlands data.