Skip to content

Commit

Permalink
feat: 修改私有资产接口实现方案
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Jan 6, 2024
1 parent d60c324 commit b00b335
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: 获取收益加成卡数据
name: 获取收益加成卡信息
type: http
seq: 4
}
Expand Down
60 changes: 37 additions & 23 deletions jkit/private/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._constraints import (
NonEmptyStr,
NonNegativeFloat,
NormalizedDatetime,
PositiveInt,
)
Expand All @@ -17,7 +18,7 @@
from jkit.credential import JianshuCredential


class AssetsTransactionHistoryRecord(DataObject, **DATA_OBJECT_CONFIG):
class AssetsTransactionRecord(DataObject, **DATA_OBJECT_CONFIG):
id: PositiveInt # noqa: A003
time: NormalizedDatetime
type_id: PositiveInt
Expand All @@ -26,13 +27,26 @@ class AssetsTransactionHistoryRecord(DataObject, **DATA_OBJECT_CONFIG):
amount_precise: Decimal


class AssetsTransactionHistory(ResourceObject):
class FPRewardsRecord(DataObject, **DATA_OBJECT_CONFIG):
time: NormalizedDatetime
own_amount: Decimal
referral_amount: Decimal
grand_referral_amount: Decimal
total_amount: Decimal


class BenefitCardsInfo(DataObject, **DATA_OBJECT_CONFIG):
total_amount: NonNegativeFloat
estimated_benefits_percent: NonNegativeFloat


class Assets(ResourceObject):
def __init__(self, *, credential: JianshuCredential) -> None:
self._credential = credential

async def iter_fp_records(
self, *, max_id: Optional[int] = None
) -> AsyncGenerator[AssetsTransactionHistoryRecord, None]:
) -> AsyncGenerator[AssetsTransactionRecord, None]:
now_max_id = max_id

while True:
Expand All @@ -51,7 +65,7 @@ async def iter_fp_records(

for item in data["transactions"]:
is_out = item["io_type"] == 2
yield AssetsTransactionHistoryRecord(
yield AssetsTransactionRecord(
id=item["id"],
time=normalize_datetime(item["time"]),
type_id=item["tn_type"],
Expand All @@ -65,7 +79,7 @@ async def iter_fp_records(

async def iter_ftn_records(
self, *, max_id: Optional[int] = None
) -> AsyncGenerator[AssetsTransactionHistoryRecord, None]:
) -> AsyncGenerator[AssetsTransactionRecord, None]:
now_max_id = max_id

while True:
Expand All @@ -84,7 +98,7 @@ async def iter_ftn_records(

for item in data["transactions"]:
is_out = item["io_type"] == 2
yield AssetsTransactionHistoryRecord(
yield AssetsTransactionRecord(
id=item["id"],
time=normalize_datetime(item["time"]),
type_id=item["tn_type"],
Expand All @@ -96,22 +110,9 @@ async def iter_ftn_records(
),
)._validate()


class FPRewardsHistoryRecord(DataObject, **DATA_OBJECT_CONFIG):
time: NormalizedDatetime
own_amount: Decimal
referral_amount: Decimal
grand_referral_amount: Decimal
total_amount: Decimal


class FPRewardsHistory(ResourceObject):
def __init__(self, *, credential: JianshuCredential) -> None:
self._credential = credential

async def iter_records(
self, page_size: int = 10
) -> AsyncGenerator[FPRewardsHistoryRecord, None]:
async def iter_fp_rewards_records(
self, *, page_size: int = 10
) -> AsyncGenerator[FPRewardsRecord, None]:
now_page = 1

while True:
Expand All @@ -125,7 +126,7 @@ async def iter_records(
return

for item in data["transactions"]:
yield FPRewardsHistoryRecord(
yield FPRewardsRecord(
time=normalize_datetime(item["time"]),
own_amount=normalize_assets_amount_precise(item["own_reards18"]),
referral_amount=normalize_assets_amount_precise(
Expand All @@ -140,3 +141,16 @@ async def iter_records(
)._validate()

now_page += 1

@property
async def benefit_cards_info(self) -> BenefitCardsInfo:
data = await get_json(
endpoint=ENDPOINT_CONFIG.jianshu,
path="/asimov/fp_wallets/benefit_cards/info",
cookies=self._credential.cookies,
)

return BenefitCardsInfo(
total_amount=float(normalize_assets_amount_precise(data["total_amount18"])),
estimated_benefits_percent=data["total_estimated_benefits"] / 100,
)._validate()

0 comments on commit b00b335

Please sign in to comment.