-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (28 loc) · 1.04 KB
/
main.py
File metadata and controls
34 lines (28 loc) · 1.04 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
# import system module to read command line arguments
import sys
# import local modules
import PubMedParse
import REACHProcess
import ParseException
# We should have at least one PMID
if len(sys.argv) < 2:
raise Exception("You should provide at least one PMID as command line argument.")
# initialize PubMed parser
parser = PubMedParse.PubMedParser()
# initialize REACH web-service processing
reach = REACHProcess.REACHProcessor()
# iterate over all available PMIDs
for PMID in sys.argv[1:]:
try:
print ("Get data for PMID {0:s}".format(PMID))
# extract abstract for the specific PMID
Abstract = parser.parse(PMID)
# get REACH data for the specific Abstract
reach_result = reach.process_REACH(PMID, Abstract)
# write result into a file
json_file = open("{0:s}.json".format(PMID), 'w+')
json_file.write(reach_result)
json_file.close()
except ParseException.ParseException as err:
print("There is a parsing error: {0:s}".format(err.message))
sys.exit(255)