-
Notifications
You must be signed in to change notification settings - Fork 1
/
calling_becas_api.py
56 lines (39 loc) · 1.64 KB
/
calling_becas_api.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
45
46
47
48
49
50
51
52
53
54
55
56
def call_becas_api(geo_info):
import becas
import logging
import requests
becas.email = 'rb7.itr7@gmail.com'
metadata_becas ={}
invalid_geo_ids = []
geo_id = geo_info['gse_id']
#logging.info(geo_id)
count = 0
summary_count = 0
abstract_count = 0
summary = geo_info['summary']
pmid = geo_info['PMID']
if pmid == None:
results = becas.annotate_text(summary)
summary_count += 1
print('No PMID for {}'.format(geo_id))
print('Extracting summary')
#logging.info('No PMID for' + ' ' + geo_id + ' so extracting summary')
else:
url_test = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id="+geo_info['PMID']+"&retmode=json&rettype=abstract"
Response_test = requests.get(url_test)
abstract = Response_test.text.replace("\n", "")
try:
results = becas.annotate_text(abstract)
print('Extracting abstract')
#logging.info('PMID available for' ' ' + geo_id + ' ' + 'so extracting abstract')
except becas.BecasException:
invalid_geo_ids.append(geo_id)
summary_count-= 1
print('500 Server Error: Internal Server Error for BecasException for {}'.format(geo_ids))
#logging.exception("Exception occurred")
abstract_count += 1
count+= 1
print('Fetched info of {} {} id'.format(count, geo_id))
results = becas.annotate_text(summary)
metadata_becas[geo_id] = results
return metadata_becas