Skip to content

22 fetch metadata from apis#24

Draft
ClaireHzl wants to merge 21 commits intomainfrom
22-fetch-metadata-from-apis
Draft

22 fetch metadata from apis#24
ClaireHzl wants to merge 21 commits intomainfrom
22-fetch-metadata-from-apis

Conversation

@ClaireHzl
Copy link
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
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
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
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
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
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

return False
try:
for pdf_url in pdf_urls:
response = requests.get(pdf_url, timeout=30)
Copy link
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
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
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
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 True
return False
except Exception as e:
print(f"Download failed: {e}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

logging à la place de print.

return []


if __name__ == "__main__":
Copy link
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

return {"found": bool(sources), "sources": sources} | merged


if __name__ == "__main__":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ici ce serait mieux d'intégrer ca directement dans fetch_file_and_metadata de services.py

## Usage

```bash
python3 main.py --doi 10.1128/mbio.01735-25
Copy link
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

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