-
Notifications
You must be signed in to change notification settings - Fork 4
/
model.py
65 lines (52 loc) · 1.6 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from dataclasses import dataclass
from datetime import date
from enum import Enum
from bs4 import BeautifulSoup
from functional import seq
from roam import roam_date
class Color(Enum):
"""
Probably most hacky part of this. Logic is that the colors are represented by images with the given index
"""
BLUE = 1
RED = 2
YELLOW = 3
GREEN = 4
@dataclass
class Highlight:
book: str
text: str
note: str
link: str
page: str
date: date
color: Color
@property
def markdown_link(self):
return f'[{self.book}: {self.page}]({self.link})'
@property
def color_attribute(self):
return f'color::#{self.color.name.lower()}'
@property
def date_attribute(self):
return f'date::[[{roam_date(self.date)}]]'
def as_roam_block_hierarchy(self):
return {
self.text: ([{self.note: []}] if self.note else []) + [
{self.markdown_link: []},
{self.date_attribute: []},
{self.color_attribute: []},
]
}
def as_roam_markdown(self):
return seq(
f' - {self.text}',
f' - {self.note}' if self.note else None,
f' - {self.markdown_link}',
f' - {self.date_attribute}',
f' - {self.color_attribute}'
).filter(lambda it: it is not None).make_string('\n')
def as_anki_csv_row(self):
soup = BeautifulSoup()
link = soup.new_tag('a', href=self.link, string=f'{self.book}: {self.page}')
return [self.text, self.note, link, str(self.date), self.color.name.lower()]