SIMNet/simnet/models/genshin/diary.py

120 lines
2.7 KiB
Python
Raw Normal View History

2023-06-09 03:48:56 +00:00
from datetime import datetime
2024-05-24 15:01:00 +00:00
from typing import List, Optional
2023-06-09 03:48:56 +00:00
from pydantic import Field
from simnet.models.base import APIModel
from simnet.models.diary import BaseDiary
__all__ = (
"DayDiaryData",
"Diary",
"DiaryAction",
"DiaryActionCategory",
"DiaryPage",
"MonthDiaryData",
)
class DiaryActionCategory(APIModel):
"""Diary category for primogems.
Attributes:
id: Category ID.
name: Category name.
amount: Amount of primogems.
percentage: Percentage of primogems.
"""
id: int = Field(alias="action_id")
name: str = Field(alias="action")
amount: int = Field(alias="num")
percentage: int = Field(alias="percent")
class MonthDiaryData(APIModel):
"""Diary data for a month.
Attributes:
current_primogems: Current amount of primogems.
current_mora: Current amount of mora.
last_primogems: Last amount of primogems.
last_mora: Last amount of mora.
primogems_rate: Primogems rate.
mora_rate: Mora rate.
categories: List of diary categories.
"""
current_primogems: int
current_mora: int
last_primogems: int
last_mora: int
2023-09-06 03:57:35 +00:00
primogems_rate: int = Field(aliases="primogem_rate")
2023-06-09 03:48:56 +00:00
mora_rate: int
categories: List[DiaryActionCategory] = Field(alias="group_by")
class DayDiaryData(APIModel):
"""Diary data for a day.
Attributes:
current_primogems: Current amount of primogems.
current_mora: Current amount of mora.
"""
current_primogems: int
current_mora: int
class Diary(BaseDiary):
"""Traveler's diary.
Attributes:
data: Diary data for a month.
day_data: Diary data for a day.
date: Request date.
2023-06-09 03:48:56 +00:00
"""
data: MonthDiaryData = Field(alias="month_data")
day_data: DayDiaryData
2024-05-24 15:01:00 +00:00
date: Optional[str] = ""
@property
def data_id(self) -> int:
"""Get the data ID."""
2024-05-24 15:01:00 +00:00
date = (self.date or datetime.now().strftime("%Y-%m-%d")).split("-")
year, month = int(date[0]), int(date[1])
if month < self.month:
year -= 1
return year * 100 + self.month
2023-06-09 03:48:56 +00:00
@property
def month_data(self) -> MonthDiaryData:
return self.data
class DiaryAction(APIModel):
"""Action which earned currency.
Attributes:
action_id: Action ID.
action: Action name.
time: Time of the action.
amount: Amount of the action.
"""
action_id: int
action: str
time: datetime = Field(timezone=8)
amount: int = Field(alias="num")
class DiaryPage(BaseDiary):
"""Page of a diary.
Attributes:
actions: List of diary actions.
"""
actions: List[DiaryAction] = Field(alias="list")