[lifeevents] Add metadata dataclasses

This commit is contained in:
2024-05-23 00:16:24 -04:00
parent e15d253d58
commit 1cceb2bd63
2 changed files with 58 additions and 1 deletions

View File

@ -2,7 +2,7 @@ from django.apps import apps
from django.db import models
from django.urls import reverse
import pendulum
from lifeevents.dataclasses import LifeEventMetadata
from scrobbles.dataclasses import LifeEventMetadata
from scrobbles.mixins import ScrobblableMixin
BNULL = {"blank": True, "null": True}

View File

@ -0,0 +1,57 @@
import json
from dataclasses import dataclass, asdict
from typing import Optional
class JSONMetadata(object):
@property
def asdict(self):
return asdict(self)
@property
def json(self):
return json.dumps(self.asdict)
@dataclass
class BoardGameScore(JSONMetadata):
user_id: int
score: Optional[int]
win: Optional[bool]
@dataclass
class BoardGameMetadata(JSONMetadata):
players: Optional[list[BoardGameScore]]
@dataclass
class LifeEventMetadata(JSONMetadata):
location: Optional[str]
geo_location_id: Optional[int]
participant_user_ids: Optional[list[int]]
@property
def __dict__(self):
return asdict(self)
@property
def json(self):
return json.dumps(self.__dict__)
@dataclass
class VideoMetadata(JSONMetadata):
title: str
video_type: str
run_time_seconds: int
kind: str
year: Optional[int]
episode_number: Optional[int]
source_url: Optional[str]
imdbID: Optional[str]
season_number: Optional[int]
cover_url = Optional[str]
next_imdb_id: Optional[int]
tv_series_id: Optional[str]