Skip to content

Commit

Permalink
feat: Pass config filepath to the ZoteroItemBase instead of the rende…
Browse files Browse the repository at this point in the history
…red dictionary.

Rename `output_params` to `params_filepath`.
  • Loading branch information
e-alizadeh committed Dec 29, 2021
1 parent 0011d3a commit af3e78e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
19 changes: 6 additions & 13 deletions zotero2md/generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
from argparse import ArgumentParser
from pathlib import Path
from typing import Dict, Optional, Union
from typing import Union

from pyzotero.zotero import Zotero

Expand All @@ -23,7 +21,7 @@


def generate_annotations_for_all_items(
zotero_client: Zotero, output_params: Optional[Union[Dict, None]] = None
zotero_client: Zotero, params_filepath: Union[str, None] = None
) -> None:
highlights = group_annotations_by_parent_file(
retrieve_all_annotations(zotero_client)
Expand All @@ -34,7 +32,7 @@ def generate_annotations_for_all_items(
print(f"File {i + 1} of {len(highlights)} is under process ...")
item = ItemAnnotations(
zotero_client=zotero_client,
md_params=output_params,
params_filepath=params_filepath,
item_annotations=highlights[item_key],
item_key=item_key,
)
Expand All @@ -58,11 +56,6 @@ def generate_annotations_for_all_items(
api_key=args["zotero_key"],
)

if args.get("config_filepath", None):
config_filepath = Path(args["config_filepath"])
with open(config_filepath, "r") as f:
params = json.load(f)
else:
params = None

generate_annotations_for_all_items(zotero_client, output_params=params)
generate_annotations_for_all_items(
zotero_client, params_filepath=args.get("config_filepath", None)
)
13 changes: 8 additions & 5 deletions zotero2md/zotero.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path
from typing import Dict, List, Tuple, Union

Expand All @@ -12,14 +13,16 @@


class ZoteroItemBase:
def __init__(self, zotero_client: Zotero, md_params: Dict = None):
def __init__(self, zotero_client: Zotero, params_filepath: Union[str, None] = None):
self.zotero = zotero_client

# Load output configurations used for generating markdown files.
self.md_config = default_params

if md_params:
self.md_config = {**self.md_config, **md_params}
if params_filepath:
with open(Path(params_filepath), "r") as f:
params = json.load(f)
self.md_config = {**self.md_config, **params}

def get_item_metadata(self, item_details: Dict) -> Dict:
if "parentItem" in item_details["data"]:
Expand Down Expand Up @@ -82,11 +85,11 @@ class ItemAnnotations(ZoteroItemBase):
def __init__(
self,
zotero_client: Zotero,
md_params: Union[Dict, None],
item_annotations: List[Dict],
item_key: str,
params_filepath: Union[str, None] = None,
):
super().__init__(zotero_client, md_params)
super().__init__(zotero_client, params_filepath)
self.item_annotations = item_annotations
self.item_key = item_key
self.item_details = self.zotero.item(self.item_key)
Expand Down

0 comments on commit af3e78e

Please sign in to comment.