-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadpmids.py
More file actions
executable file
·43 lines (34 loc) · 1.28 KB
/
loadpmids.py
File metadata and controls
executable file
·43 lines (34 loc) · 1.28 KB
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
#!/usr/bin/env python
import rich
import rich.pretty
import eutilsutils
import eutilsutils.parser
app = eutilsutils.EutilsUtils()
import time
mylog = []
def append_log(theresult):
mylog.append((
theresult['Count'],
theresult['WebEnv'],
theresult['QueryKey']
))
with app.en.esearch(db='pubmed', term='Heart Failure', usehistory='y') as sh:
result = app.en.read(sh)
append_log(result)
with app.en.esearch(db='pubmed', term='artificial intelligence OR machine learning OR deep learning', usehistory='y', WebEnv=result['WebEnv']) as sh:
result = app.en.read(sh)
append_log(result)
with app.en.esearch(db='pubmed', term='(#1) AND (#2) AND english[la]', usehistory='y', WebEnv=result['WebEnv']) as sh:
result = app.en.read(sh)
append_log(result)
rich.pretty.pprint(mylog)
step = 500
load_log = []
for i in range(0,int(result['Count']),step):
rich.print(f"Requesting {i} to {i+step} ...", end=" ")
with app.en.efetch(db='pubmed', query_key=result['QueryKey'], WebEnv=result['WebEnv'], retstart=i, retmax=step) as fh:
fetched = app.en.read(fh)
rich.print(f"Parsing {len(fetched['PubmedArticle'])}",end=" ")
load_log.extend(eutilsutils.parser.loadEfetch2PMPapers(app,fetched,False))
rich.print(f"Parsed")
time.sleep(3)