File size: 1,147 Bytes
25f22bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from dataclasses import dataclass
from typing import Optional
from datetime import datetime
@dataclass
class Schedule:
"""Schedule model representing a post scheduling configuration."""
id: str
social_account_id: str
schedule_time: str
adjusted_time: str
created_at: Optional[datetime] = None
@classmethod
def from_dict(cls, data: dict):
"""Create a Schedule instance from a dictionary."""
return cls(
id=data['id'],
social_account_id=data['social_account_id'],
schedule_time=data['schedule_time'],
adjusted_time=data['adjusted_time'],
created_at=datetime.fromisoformat(data['created_at'].replace('Z', '+00:00')) if data.get('created_at') else None
)
def to_dict(self):
"""Convert Schedule instance to dictionary."""
return {
'id': self.id,
'social_account_id': self.social_account_id,
'schedule_time': self.schedule_time,
'adjusted_time': self.adjusted_time,
'created_at': self.created_at.isoformat() if self.created_at else None
} |