diff --git a/zotero2readwise/run.py b/zotero2readwise/run.py index 96576f7..fe392d5 100644 --- a/zotero2readwise/run.py +++ b/zotero2readwise/run.py @@ -33,6 +33,13 @@ default="n", help="Include Zotero notes | Options: 'y'/'yes' (default), 'n'/'no'", ) + parser.add_argument( + "--filter_color", + choices=['#ffd400', '#ff6666', '#5fb236', '#2ea8e5', '#a28ae5', '#e56eee', '#f19837', '#aaaaaa'], + action="append", + default=[], + help="Filter Zotero annotations by given color | Options: '#ffd400' (yellow), '#ff6666' (red), '#5fb236' (green), '#2ea8e5' (blue), '#a28ae5' (purple), '#e56eee' (magenta), '#f19837' (orange), '#aaaaaa' (gray)" + ) args = vars(parser.parse_args()) @@ -52,5 +59,6 @@ zotero_library_type=args["library_type"], include_annotations=args["include_annotations"], include_notes=args["include_notes"], + filter_colors=args["filter_color"] ) zt2rw.run() diff --git a/zotero2readwise/zotero.py b/zotero2readwise/zotero.py index 6d4322f..ee14e76 100644 --- a/zotero2readwise/zotero.py +++ b/zotero2readwise/zotero.py @@ -101,11 +101,12 @@ def get_zotero_client( class ZoteroAnnotationsNotes: - def __init__(self, zotero_client: Zotero): + def __init__(self, zotero_client: Zotero, filter_colors: List[str]): self.zot = zotero_client self.failed_items: List[Dict] = [] self._cache: Dict = {} self._parent_mapping: Dict = {} + self.filter_colors: List[str] = filter_colors def get_item_metadata(self, annot: Dict) -> Dict: data = annot["data"] @@ -201,7 +202,8 @@ def format_items(self, annots: List[Dict]) -> List[ZoteroItem]: ) for annot in annots: try: - formatted_annots.append(self.format_item(annot)) + if len(self.filter_colors) == 0 or annot["data"]["annotationColor"] in self.filter_colors: + formatted_annots.append(self.format_item(annot)) except: self.failed_items.append(annot) continue diff --git a/zotero2readwise/zt2rw.py b/zotero2readwise/zt2rw.py index daad57b..b0301e5 100644 --- a/zotero2readwise/zt2rw.py +++ b/zotero2readwise/zt2rw.py @@ -18,6 +18,7 @@ def __init__( zotero_library_type: str = "user", include_annotations: bool = True, include_notes: bool = False, + filter_colors: List[str] = [] ): self.readwise = Readwise(readwise_token) self.zotero_client = get_zotero_client( @@ -25,7 +26,7 @@ def __init__( library_type=zotero_library_type, api_key=zotero_key, ) - self.zotero = ZoteroAnnotationsNotes(self.zotero_client) + self.zotero = ZoteroAnnotationsNotes(self.zotero_client, filter_colors) self.include_annots = include_annotations self.include_notes = include_notes