Skip to content

22 fetch metadata from apis#24

Merged
cgoudet merged 25 commits intomainfrom
22-fetch-metadata-from-apis
Mar 29, 2026
Merged

22 fetch metadata from apis#24
cgoudet merged 25 commits intomainfrom
22-fetch-metadata-from-apis

Conversation

@ClaireHzl
Copy link
Copy Markdown
Collaborator

Script that retrieves metadata for a specific article using various APIs based on its DOI and downloads its PDF if it is open access.

@ClaireHzl ClaireHzl linked an issue Mar 16, 2026 that may be closed by this pull request
@ClaireHzl ClaireHzl marked this pull request as draft March 16, 2026 13:10
Copy link
Copy Markdown
Collaborator

@cgoudet cgoudet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci pour ce travail!

Il faudrait tout mettre en "prod" plutot qu'en exploration.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puisque l'on va les utiliser en prod, ces parsers doivent être dans la section prod et pas exploration du projet.

return [article.pdf_url] if article else []


if __name__ == "__main__":
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A plutot mettre comme un test d'intégration mais mettre un skip pour qu'ils ne soit jamais lancé dans la CI.

ARXIV_DOI_PREFIX = "10.48550/arXiv."


class ArxivMetadataParser(MetadataParser):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne me souviens plus des discussions. PAs de téléchargement possible sur pdf sur arxiv?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Téléchargement possible sur Arxiv mais pas sur Pubmed à première vue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup ici arxiv utilise le téléchargement par défaut du MetadataParser?

return False
try:
for pdf_url in pdf_urls:
response = requests.get(pdf_url, timeout=30)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour un poil plus de clarté, peut être créer une fonction dédié pour télécharger 1 fichier.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quand tu dis une fonction dédiée, tu parles d'une sous-fonction de cette fonction qui s'occupe uniquement du téléchargement en tant que tel (pour que la fonction soit moins complexe), ou de faire une fonction spécifique pour chaque classe fille ?

if not response.content.startswith(b"%PDF"):
print(f"Content at {pdf_url} is not a valid PDF (possibly a paywall page).")
continue
with open(output_path, "wb") as f:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu as plusieurs fichiers, ils vont tous s'écraser mutuellement et seul le dernier sera disponible.

Copy link
Copy Markdown
Collaborator Author

@ClaireHzl ClaireHzl Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dans la fonction, on télécharge uniquement le pdf de la première url qui n'est pas une interface de paiement. Ca peut cependant s'écraser entre les différentes API, mais dans l'idée on ne veut qu'un seul pdf par DOI non ?

return []


if __name__ == "__main__":
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil, mettre ca dans un TU

## Usage

```bash
python3 main.py --doi 10.1128/mbio.01735-25
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est une méthode d'exploration pour l'exploration, pas pour la prod qui doit utiliser l'API

Copy link
Copy Markdown
Collaborator

@cgoudet cgoudet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les tests unitaires ne passent pas. Il faut corriger ca avant de pouvoir passer en prod.

ARXIV_DOI_PREFIX = "10.48550/arXiv."


class ArxivMetadataParser(MetadataParser):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup ici arxiv utilise le téléchargement par défaut du MetadataParser?


from .base import MetadataParser

ARXIV_DOI_PREFIX = "10.48550/arXiv."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne suis pas sur de comprendre le role de ce prefix.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui on récupère l'url du pdf, et ensuite ça utilise le téléchargement par défaut de la classe mère.
Pour le prefix, c'est que l'API utilise l'ID interne d'Arxiv. Le DOI d'un article arxiv c'est le prefixe + l'ID. Donc si c'est sous cette forme là, on va utiliser directement l'ID. Mais parfois un journal publie via arXiv et le DOI ne respecte pas la convention, donc on va faire une recherche par champ DOI (mais ça marche moins bien)

@cgoudet cgoudet marked this pull request as ready for review March 29, 2026 09:31
@cgoudet cgoudet merged commit 5f496f3 into main Mar 29, 2026
1 check failed
@cgoudet cgoudet deleted the 22-fetch-metadata-from-apis branch March 29, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fetch metadata from apis.

3 participants