-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_pubmed_pull_test.py
44 lines (34 loc) · 1.12 KB
/
test_pubmed_pull_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from Bio import Entrez
from configurations.config import *
# A brief example of how to pull an article abstract based on a key word search.
# Used "fever" as a key word search which returns the article IDs.
# Then used the first article ID to pull out the article title and abstract text as an example.
my_email = mike_email
api = mike_api_key
def search(query):
Entrez.email = my_email
handle = Entrez.esearch(
db='pubmed',
sort='relevance',
retmode='xml',
term=query
)
results = Entrez.read(handle)
return results
results = search('fever')
id_list = results['IdList']
print(id_list)
def fetch_details(id_list):
# ids = ','.join(id_list)
Entrez.email = my_email
handle = Entrez.efetch(
db='pubmed',
retmode='xml',
id=id_list[0]
)
results = Entrez.read(handle)
return results
query_1 = fetch_details(id_list)
title = query_1['PubmedArticle'][0]['MedlineCitation']['Article']['ArticleTitle']
abstract_text = " ".join(query_1['PubmedArticle'][0]['MedlineCitation']['Article']['Abstract']['AbstractText'][:])
print(f"{title}\n{abstract_text}")