Last active
January 28, 2018 22:52
-
-
Save yogeek/483761052eb9a5fdeee3cc7e34abf206 to your computer and use it in GitHub Desktop.
PubMed API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # To test : | |
| # Go to https://try.jupyter.org/ | |
| # Click on "Python 3" in the up-right "New" menu | |
| # Copy the code into a cell | |
| # Modify the search terms in line 32 | |
| # Execute with "Ctrl+Enter" | |
| import sys | |
| !{sys.executable} -m pip install biopython | |
| from Bio import Entrez | |
| import json | |
| def search(query): | |
| Entrez.email = '[email protected]' | |
| handle = Entrez.esearch(db='pubmed', | |
| sort='relevance', | |
| retmax='20', | |
| retmode='xml', | |
| term=query) | |
| results = Entrez.read(handle) | |
| return results | |
| def fetch_details(id_list): | |
| ids = ','.join(id_list) | |
| Entrez.email = '[email protected]' | |
| handle = Entrez.efetch(db='pubmed', | |
| retmode='xml', | |
| id=ids) | |
| results = Entrez.read(handle) | |
| return results | |
| if __name__ == '__main__': | |
| results = search('carissa spinarum') | |
| id_list = results['IdList'] | |
| papers = fetch_details(id_list) | |
| print("") | |
| print("-------------------------------------------------------------------------------------------------------------------") | |
| print("RESULTS :") | |
| print("-------------------------------------------------------------------------------------------------------------------") | |
| print("") | |
| for i, paper in enumerate(papers['PubmedArticle']): | |
| print("%d) %s" % (i+1, paper['MedlineCitation']['Article']['ArticleTitle'])) | |
| print(json.dumps(paper['MedlineCitation']['Article']['Abstract']['AbstractText'], indent=2, separators=(',', ':'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment