Skip to content

Commit 66d4578

Browse files
authored
Merge pull request #57 from adelavega/fix/pmcid
Fix: PMCID extraction
2 parents d171c3e + 1df08d2 commit 66d4578

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/pubget/_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _add_license(article: etree.Element, metadata: Dict[str, Any]) -> None:
9090

9191
def _add_id(article_id: etree.Element, metadata: Dict[str, Any]) -> None:
9292
id_type = article_id.get("pub-id-type")
93-
if id_type not in ["pmc", "pmid", "doi"]:
93+
if id_type not in ["pmc", "pmid", "doi", "pmcid"]:
9494
return
9595
if id_type == "pmc":
9696
id_type = "pmcid"

src/pubget/_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ def get_pmcid(article: Union[etree.ElementTree, etree.Element]) -> int:
136136
pmcid = article.find(
137137
"front/article-meta/article-id[@pub-id-type='pmcid']"
138138
)
139-
if pmc is None and pmcid is None:
140-
raise ValueError("No PMC ID found in the article XML.")
141-
if pmc:
139+
140+
val = None
141+
if pmc is not None:
142142
val = pmc.text
143-
else:
144-
val = pmcid.text.replace("PMC", "")
143+
elif pmcid is not None:
144+
val = pmcid.text
145+
if val.startswith("PMC"):
146+
val = val[3:]
147+
148+
if val is None or not val.isdigit():
149+
raise ValueError("No valid PMCID found in article XML.")
145150

146151
return int(val)
147152

0 commit comments

Comments
 (0)