Skip to content

Commit

Permalink
updated libs/dspace-rest-python, added the option to fetch one item b…
Browse files Browse the repository at this point in the history
…y uuid
  • Loading branch information
jm committed Oct 29, 2024
2 parents be747d1 + 00a09e9 commit bfd7b7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/dspace-rest-python
21 changes: 16 additions & 5 deletions src/dspace/_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,26 +355,37 @@ def fetch_items(self, page_size: int = 100, limit=None):
return items[:limit]
return items

def iter_items(self, page_size: int = 100, limit: int = -1):
def iter_items(self, page_size: int = 100, limit: int = -1, uuid: str = None):
from tqdm import tqdm

url = 'core/items'
_logger.debug(f"Fetch iter [] using [{url}]")
page = 0
len_items = 0
item_key = "items"
fetch_key = "_embedded"

if uuid is not None:
fetch_key = None
url = f"{url}/{uuid}"

with tqdm(desc="Fetching items", unit=" items") as pbar:
while True:
r = self._fetch(url, self.get, "_embedded",
r = self._fetch(url, self.get, fetch_key,
params={"page": page, "size": page_size})
if r is None:
break
key = "items"
items_data = r.get(key, [])
# only one
if uuid is not None:
yield [r]
return

items_data = r.get(item_key, [])
if items_data:
len_items += len(items_data)
yield items_data
else:
_logger.warning(f"Key [{key}] does not exist in response: {r}")
_logger.warning(f"Key [{item_key}] does not exist in response: {r}")
page += 1
pbar.update(len(items_data))

Expand Down
2 changes: 1 addition & 1 deletion tools/add_metadata/add_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def update(self, item: dict) -> bool:
if date_meta is not None:
val = date_meta[0]["value"]
if len(date_meta) != 1:
_logger.critical(f"{uuid}: more than one value {date_meta}")
_logger.critical(f"{uuid}: other than one value {date_meta}")
self._info["multiple"].append(uuid)
if not self._dry_run:
val = ''
Expand Down

0 comments on commit bfd7b7b

Please sign in to comment.