my.zotero: handle colors & extract human readable
This commit is contained in:
parent
1ef2c5619e
commit
68d3385468
2 changed files with 26 additions and 9 deletions
|
@ -77,9 +77,9 @@ def _dumps_factory(**kwargs) -> Callable[[Any], str]:
|
|||
return _orjson_dumps
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
import warnings
|
||||
from .warnings import high
|
||||
|
||||
warnings.warn("You might want to install 'orjson' to support serialization for lots more types!")
|
||||
high("You might want to install 'orjson' to support serialization for lots more types!")
|
||||
|
||||
def _stdlib_dumps(obj: Any) -> str:
|
||||
return json.dumps(obj, **kwargs)
|
||||
|
|
21
my/zotero.py
21
my/zotero.py
|
@ -41,6 +41,12 @@ class Annotation:
|
|||
text: Optional[str]
|
||||
comment: Optional[str]
|
||||
tags: Sequence[str]
|
||||
color_hex: str
|
||||
"""Original hex-encoded color in zotero"""
|
||||
|
||||
@property
|
||||
def color_human(self) -> str:
|
||||
return _hex2human(self.color_hex)
|
||||
|
||||
|
||||
def annotations() -> Iterator[Res[Annotation]]:
|
||||
|
@ -56,9 +62,8 @@ def annotations() -> Iterator[Res[Annotation]]:
|
|||
|
||||
|
||||
# type -- 1 is inline; 2 is note?
|
||||
# todo color? -- for org-mode could map into priority?
|
||||
_QUERY = '''
|
||||
SELECT A.itemID, A.parentItemID, text, comment, position, path, dateAdded
|
||||
SELECT A.itemID, A.parentItemID, text, comment, color, position, path, dateAdded
|
||||
FROM itemAnnotations AS A
|
||||
LEFT JOIN itemAttachments AS F ON A.parentItemID = F.ItemID
|
||||
LEFT JOIN items AS I ON A.itemID = I.itemID
|
||||
|
@ -126,6 +131,16 @@ def _enrich_row(r, conn: sqlite3.Connection):
|
|||
return r
|
||||
|
||||
|
||||
def _hex2human(color_hex: str) -> str:
|
||||
return {
|
||||
'#ffd400': 'yellow',
|
||||
'#a28ae5': 'purple',
|
||||
'#5fb236': 'green' ,
|
||||
'#ff6666': 'red' ,
|
||||
'#2ea8e5': 'blue' ,
|
||||
}.get(color_hex, color_hex)
|
||||
|
||||
|
||||
def _parse_annotation(r: Dict) -> Annotation:
|
||||
text = r['text']
|
||||
comment = r['comment']
|
||||
|
@ -134,6 +149,7 @@ def _parse_annotation(r: Dict) -> Annotation:
|
|||
path = r['path']
|
||||
addeds = r['dateAdded']
|
||||
tags = r['tags']
|
||||
color_hex= r['color']
|
||||
|
||||
added = datetime.strptime(addeds, '%Y-%m-%d %H:%M:%S')
|
||||
added = added.replace(tzinfo=timezone.utc)
|
||||
|
@ -151,4 +167,5 @@ def _parse_annotation(r: Dict) -> Annotation:
|
|||
text=text,
|
||||
comment=comment,
|
||||
tags=tags,
|
||||
color_hex=color_hex,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue