-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.py
executable file
·53 lines (41 loc) · 1.52 KB
/
example.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
#!/usr/bin/env python
# encoding: utf-8
from richcontext import scholapi as rc_scholapi
import json
import logging
import pprint
import sys
######################################################################
## main entry point
if __name__ == "__main__":
# logging is optional: to debug, set the `logger` parameter
# when initializing the `ScholInfraAPI` object
logging.basicConfig(stream=sys.stdout, level=logging.WARNING)
logger = logging.getLogger("RichContext")
# initialize the API access
schol = rc_scholapi.ScholInfraAPI(config_file="rc.cfg", logger=None)
#source = schol.datacite
source = schol.nsfPar
# enable this for profiling -- which is quite verbose!
enable_profiling = False # True
if enable_profiling:
pr = schol.start_profiling()
# search parameters for example use cases
doi = "10.1016/j.appet.2017.07.006"
issn = "1932-6203"
title = "Empirical analysis of potential improvements for high voltage protective algorithms"
search_term = "NASA NOAA coral"
# run it...
if source.has_credentials():
responses = source.full_text_search(search_term, limit=13, exact_match=True)
# report results
if responses[0].message:
# error case
print(responses[0].message)
else:
for r in responses:
print(json.dumps(r.meta, indent=4, ensure_ascii=False))
# report performance
source.report_perf(responses[0].timing)
if enable_profiling:
schol.stop_profiling(pr)