Skip to content

Commit

Permalink
feat: 调整 _id 字段处理方式
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Feb 27, 2024
1 parent f85f508 commit 0f710e2
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 12 deletions.
2 changes: 0 additions & 2 deletions jobs/fetch_article_earning_ranking_records.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date, datetime, timedelta
from typing import List, Optional, Tuple

from bson import ObjectId
from jkit._constraints import PositiveFloat, PositiveInt
from jkit.config import CONFIG
from jkit.exceptions import ResourceUnavailableError
Expand Down Expand Up @@ -77,7 +76,6 @@ async def process_item(
author_id, author_slug = await get_author_id_and_slug(item)

return ArticleEarningRankingRecordDocument(
_id=ObjectId(),
date=target_date,
ranking=item.ranking,
article=ArticleField(
Expand Down
2 changes: 0 additions & 2 deletions jobs/fetch_assets_ranking_records.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date, datetime
from typing import List, Optional, Tuple

from bson import ObjectId
from jkit._constraints import NonNegativeFloat, PositiveFloat, PositiveInt
from jkit.config import CONFIG
from jkit.exceptions import ResourceUnavailableError
Expand Down Expand Up @@ -73,7 +72,6 @@ async def process_item(
fp_amount, ftn_amount = await get_fp_ftn_amount(item)

return AssetsRankingRecordDocument(
_id=ObjectId(),
date=target_date,
ranking=item.ranking,
fp_amount=fp_amount,
Expand Down
2 changes: 0 additions & 2 deletions jobs/fetch_daily_update_ranking_records.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date, datetime
from typing import List

from bson import ObjectId
from jkit._constraints import PositiveInt
from jkit.ranking.daily_update import DailyUpdateRanking, DailyUpdateRankingRecord
from prefect import flow
Expand Down Expand Up @@ -35,7 +34,6 @@ def process_item(
item: DailyUpdateRankingRecord, /, *, current_date: date
) -> DailyUpdateRankingRecordDocument:
return DailyUpdateRankingRecordDocument(
_id=ObjectId(),
date=current_date,
ranking=item.ranking,
days=item.days,
Expand Down
2 changes: 0 additions & 2 deletions jobs/fetch_jpep_ftn_trade_orders.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime
from typing import List, Literal, Optional

from bson import ObjectId
from jkit._constraints import (
NonNegativeInt,
PositiveFloat,
Expand Down Expand Up @@ -63,7 +62,6 @@ def process_item(
type: Literal["buy", "sell"], # noqa: A002
) -> JPEPFTNTradeOrderDocument:
return JPEPFTNTradeOrderDocument(
_id=ObjectId(),
type=type,
fetch_time=fetch_time,
order_id=item.id,
Expand Down
2 changes: 0 additions & 2 deletions jobs/fetch_lp_recommended_article_records.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date, datetime
from typing import List, Optional

from bson import ObjectId
from jkit._constraints import (
ArticleSlug,
NonEmptyStr,
Expand Down Expand Up @@ -73,7 +72,6 @@ async def process_item(
return None

return LPRecommendedArticleRecord(
_id=ObjectId(),
date=current_date,
id=item.id,
slug=item.slug,
Expand Down
5 changes: 3 additions & 2 deletions utils/document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class Field(Struct, **FIELD_OBJECT_CONFIG):


class Documemt(Struct, **DOCUMENT_OBJECT_CONFIG):
_id: ObjectId

def validate(self) -> Self:
return convert(
to_builtins(self, builtin_types=_BUILDIN_TYPES),
Expand All @@ -44,6 +42,9 @@ def validate(self) -> Self:

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> Self:
if not hasattr(cls, "_id") and "_id" in data:
del data["_id"]

return convert(data, type=cls)

def to_dict(self) -> Dict[str, Any]:
Expand Down

0 comments on commit 0f710e2

Please sign in to comment.