Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Add get_lastclaim and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
FerranMarin committed Dec 28, 2021
1 parent b8a7440 commit b4145ed
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
5 changes: 3 additions & 2 deletions axie-utils/axie_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.1.0'
__version__ = '1.1.1'
__all__ = [
'Axies',
'AxieGraphQL',
Expand All @@ -16,6 +16,7 @@
'TrezorPayment',
'TrezorTransfer',
'get_nonce',
'get_lastclaim',
'check_balance',
]

Expand All @@ -26,4 +27,4 @@
from axie_utils.morphing import Morph, TrezorMorph
from axie_utils.payments import Payment, TrezorPayment
from axie_utils.transfers import Transfer, TrezorTransfer
from axie_utils.utils import get_nonce, check_balance, CustomUI, TrezorConfig
from axie_utils.utils import get_nonce, check_balance, CustomUI, TrezorConfig, get_lastclaim
19 changes: 19 additions & 0 deletions axie-utils/axie_utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import logging
from datetime import datetime
from json.decoder import JSONDecodeError

import requests
from requests.packages.urllib3.util.retry import Retry
from web3 import Web3
from trezorlib.ui import ClickUI
Expand Down Expand Up @@ -66,6 +71,20 @@ def get_nonce(account):
return nonce


def get_lastclaim(account):
url = f'https://game-api.skymavis.com/game-api/clients/{account.replace("ronin:", "0x")}/items/1'
try:
r = requests.get(url)
rjs = r.json()
if rjs.get('last_claimed_item_at'):
date = datetime.fromtimestamp(rjs['last_claimed_item_at'])
return date
except JSONDecodeError:
logging.critical('Something went wrong getting last claim')

return None


class CustomUI(ClickUI):
def __init__(self, passphrase=None, *args, **kwargs):
self.passphrase = passphrase
Expand Down
2 changes: 1 addition & 1 deletion axie-utils/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "axie-utils"
version = "1.1.0"
version = "1.1.1"
description = "Library that provides the functionality you need to build your own axie Infinity python tools"
authors = ["Ferran Marin <ferran.marin.llobet@gmail.com>"]
license = "GNU LGPLv3"
Expand Down
3 changes: 2 additions & 1 deletion axie-utils/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_version():
assert axie_utils.__version__ == '1.1.0'
assert axie_utils.__version__ == '1.1.1'


def test_init():
Expand All @@ -23,4 +23,5 @@ def test_init():
'TrezorPayment',
'TrezorTransfer',
'get_nonce',
'get_lastclaim',
'check_balance']
35 changes: 34 additions & 1 deletion axie-utils/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from datetime import datetime

from mock import patch
import requests_mock

from axie_utils import TrezorConfig
from axie_utils import TrezorConfig, get_lastclaim


def test_trezor_config_init():
Expand All @@ -22,3 +25,33 @@ def test_trezor_list_paths(mock_get_client, mocked_get_address, mocked_parse_pat
mocked_parse_path.assert_called_with("m/44'/60'/0'/0/0")
mocked_get_address.assert_called_with('client', 'path', True)
assert resp == {"ronin:bar": {"passphrase": "foo", "bip_path": "m/44'/60'/0'/0/0"}}


def test_get_lastclaim():
account = 'ronin:abc'
url = f'https://game-api.skymavis.com/game-api/clients/{account.replace("ronin:", "0x")}/items/1'
with requests_mock.Mocker() as req_mocker:
req_mocker.get(url, json={"last_claimed_item_at": 1640649715})
d = get_lastclaim(account)

assert d == datetime(2021, 12, 28, 0, 1, 55)


def test_get_lastclaim_missing_data():
account = 'ronin:abc'
url = f'https://game-api.skymavis.com/game-api/clients/{account.replace("ronin:", "0x")}/items/1'
with requests_mock.Mocker() as req_mocker:
req_mocker.get(url,json={"foo": "bar"})
d = get_lastclaim(account)

assert d == None


def test_get_lastclaim_no_json():
account = 'ronin:abc'
url = f'https://game-api.skymavis.com/game-api/clients/{account.replace("ronin:", "0x")}/items/1'
with requests_mock.Mocker() as req_mocker:
req_mocker.get(url)
d = get_lastclaim(account)

assert d == None

0 comments on commit b4145ed

Please sign in to comment.