-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
37 lines (32 loc) · 881 Bytes
/
model.py
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
34
35
36
37
from munch import Munch
from typing import List
from datetime import datetime
import json
class JsonEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
return o.isoformat()
return json.JSONEncoder.default(self, o)
class Base(Munch):
def __init__(self, **kwargs):
for key, typ in self.__annotations__.items():
assert key in kwargs, f'missing field {key}'
val = kwargs[key]
assert isinstance(val, typ), f'field {key}:{val} is not instance of type {typ}'
super().__init__(**kwargs)
class Post(Base):
title: str
link: str
score: int
user: str
date: datetime
comments: str
comment_count: int
source: str
class Content(Base):
post: Post
article: str
density: float
length: int
# summary: str
# keywords: List[str]