Add calendar implementation: models, storage, CLI

This commit is contained in:
Дедов Егор Сергеевич
2026-05-18 14:51:05 +03:00
parent 2a35a9ce78
commit 816c9f1cda
6 changed files with 228 additions and 0 deletions

35
models.py Normal file
View File

@@ -0,0 +1,35 @@
import json
from datetime import datetime
from typing import List, Optional
class Event:
"""Класс события календаря"""
def __init__(self, title: str, date: str, time: str = "", description: str = ""):
self.title = title
self.date = date # формат YYYY-MM-DD
self.time = time # формат HH:MM
self.description = description
def to_dict(self) -> dict:
"""Преобразует событие в словарь для JSON"""
return {
"title": self.title,
"date": self.date,
"time": self.time,
"description": self.description
}
@classmethod
def from_dict(cls, data: dict) -> 'Event':
"""Создаёт событие из словаря"""
return cls(
title=data["title"],
date=data["date"],
time=data.get("time", ""),
description=data.get("description", "")
)
def __str__(self) -> str:
time_str = f" в {self.time}" if self.time else ""
return f"{self.date}{time_str}: {self.title} - {self.description}"