Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pubget/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ def extract(
for part_name in self.fields:
elem = transformed.find(part_name)
result[part_name] = elem.text
result["pmcid"] = int(result["pmcid"])
result["pmcid"] = _utils.get_pmcid(article)
return result
13 changes: 11 additions & 2 deletions src/pubget/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ def load_stylesheet(stylesheet_name: str) -> etree.XSLT:

def get_pmcid(article: Union[etree.ElementTree, etree.Element]) -> int:
"""Extract the PubMedCentral ID from an XML article."""
return int(
article.find("front/article-meta/article-id[@pub-id-type='pmc']").text
pmc = article.find("front/article-meta/article-id[@pub-id-type='pmc']")
pmcid = article.find(
"front/article-meta/article-id[@pub-id-type='pmcid']"
)
if pmc is None and pmcid is None:
raise ValueError("No PMC ID found in the article XML.")
if pmc:
val = pmc.text
else:
val = pmcid.text.replace("PMC", "")

return int(val)


def get_pmcid_from_article_dir(article_dir: Path) -> int:
Expand Down
Loading