-
Notifications
You must be signed in to change notification settings - Fork 168
/
basic_document.py
46 lines (38 loc) · 1.06 KB
/
basic_document.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
38
39
40
41
42
43
44
45
from datetime import datetime
from dataclasses import dataclass
from enum import Enum
class DocumentType(Enum):
DOCUMENT = "document"
MESSAGE = "message"
COMMENT = "comment"
PERSON = "person"
class FileType(Enum):
GOOGLE_DOC = "doc"
DOCX = "docx"
PPTX = "pptx"
TXT = "txt"
@classmethod
def from_mime_type(cls, mime_type: str):
if mime_type == 'application/vnd.google-apps.document':
return cls.GOOGLE_DOC
elif mime_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
return cls.DOCX
elif mime_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
return cls.PPTX
elif mime_type == 'text/plain':
return cls.TXT
else:
return None
@dataclass
class BasicDocument:
id: int
data_source_id: int
type: DocumentType
title: str
content: str
timestamp: datetime
author: str
author_image_url: str
location: str
url: str
file_type: FileType = None