Cleaned and improved
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""TV Show models and validation."""
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
|
||||
class ShowStatus(Enum):
|
||||
"""Status of a TV show - whether it's still airing or has ended."""
|
||||
ONGOING = "ongoing"
|
||||
ENDED = "ended"
|
||||
|
||||
|
||||
@dataclass
|
||||
class TVShow:
|
||||
"""Represents a TV show."""
|
||||
imdb_id: str
|
||||
title: str
|
||||
seasons_count: int
|
||||
status: ShowStatus # ongoing or ended
|
||||
|
||||
|
||||
def validate_tv_shows_structure(tv_shows: Any) -> bool:
|
||||
"""
|
||||
Validate the structure of the tv_shows parameter.
|
||||
|
||||
Expected structure: list of TV show objects
|
||||
[
|
||||
{
|
||||
"imdb_id": str,
|
||||
"title": str,
|
||||
"seasons_count": int,
|
||||
"status": str # "ongoing" or "ended"
|
||||
}
|
||||
]
|
||||
"""
|
||||
if not isinstance(tv_shows, list):
|
||||
return False
|
||||
|
||||
for show in tv_shows:
|
||||
if not isinstance(show, dict):
|
||||
return False
|
||||
|
||||
# Check required fields
|
||||
required_fields = {"imdb_id", "title", "seasons_count", "status"}
|
||||
if not all(field in show for field in required_fields):
|
||||
return False
|
||||
|
||||
# Validate field types
|
||||
if not isinstance(show["imdb_id"], str):
|
||||
return False
|
||||
if not isinstance(show["title"], str):
|
||||
return False
|
||||
if not isinstance(show["seasons_count"], int):
|
||||
return False
|
||||
if show["status"] not in ["ongoing", "ended"]:
|
||||
return False
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user