diff --git "a/jianshu_apis/\347\247\201\346\234\211 - \350\265\204\344\272\247/\350\216\267\345\217\226\346\224\266\347\233\212\345\212\240\346\210\220\345\215\241\346\225\260\346\215\256.bru" "b/jianshu_apis/\347\247\201\346\234\211 - \350\265\204\344\272\247/\350\216\267\345\217\226\346\224\266\347\233\212\345\212\240\346\210\220\345\215\241\344\277\241\346\201\257.bru" similarity index 82% rename from "jianshu_apis/\347\247\201\346\234\211 - \350\265\204\344\272\247/\350\216\267\345\217\226\346\224\266\347\233\212\345\212\240\346\210\220\345\215\241\346\225\260\346\215\256.bru" rename to "jianshu_apis/\347\247\201\346\234\211 - \350\265\204\344\272\247/\350\216\267\345\217\226\346\224\266\347\233\212\345\212\240\346\210\220\345\215\241\344\277\241\346\201\257.bru" index 4a2cd1d..456139d 100644 --- "a/jianshu_apis/\347\247\201\346\234\211 - \350\265\204\344\272\247/\350\216\267\345\217\226\346\224\266\347\233\212\345\212\240\346\210\220\345\215\241\346\225\260\346\215\256.bru" +++ "b/jianshu_apis/\347\247\201\346\234\211 - \350\265\204\344\272\247/\350\216\267\345\217\226\346\224\266\347\233\212\345\212\240\346\210\220\345\215\241\344\277\241\346\201\257.bru" @@ -1,5 +1,5 @@ meta { - name: 获取收益加成卡数据 + name: 获取收益加成卡信息 type: http seq: 4 } diff --git a/jkit/private/assets.py b/jkit/private/assets.py index aaf7614..87c3736 100644 --- a/jkit/private/assets.py +++ b/jkit/private/assets.py @@ -4,6 +4,7 @@ from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject from jkit._constraints import ( NonEmptyStr, + NonNegativeFloat, NormalizedDatetime, PositiveInt, ) @@ -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 @@ -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: @@ -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"], @@ -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: @@ -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"], @@ -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: @@ -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( @@ -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()