SeaCogs/aurora/utilities/encoder.py
SeaswimmerTheFsh ca1722fee3
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Successful in 35s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 51s
feat(aurora): migrated to a custom json encoder
2024-05-04 15:05:50 -04:00

15 lines
399 B
Python

import json
from datetime import datetime, timedelta
from aurora.models import Moderation
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
return int(o.timestamp())
if isinstance(o, timedelta):
return str(o)
if isinstance(o, Moderation):
return o.model_dump()
return super().default(o)