forked from OpenTreeOfLife/opentree-testrunner
/
test_taxo_tnrs.py
executable file
·42 lines (38 loc) · 1.37 KB
/
test_taxo_tnrs.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
#!/usr/bin/env python
import sys
import requests
import json
#curl -X POST http://opentree-dev.bio.ku.edu:7474/ext/TNRS/graphdb/doTNRSForNames -H "Content-Type: Application/json" -d '{"queryString": "Pan trodlogytes, Homo sapphire, Plantago, Morpho peleides, Eleocharis"}'
from opentreetesting import config
DOMAIN = config('host', 'tnrshost')
SUBMIT_URI = DOMAIN + '/ext/TNRS/graphdb/doTNRSForNames'
payload = {
"queryString": "Pan trodlogytes, Homo sapphire, Plantago, Morpho peleides, Eleocharis",
"contextName": "All life"
}
if len(sys.argv) > 1:
payload['queryString'] = ', '.join(sys.argv[1:])
headers = {
'content-type' : 'application/json',
'accept' : 'application/json',
}
resp = requests.post(SUBMIT_URI,
headers=headers,
data=json.dumps(payload),
allow_redirects=True)
sys.stderr.write('Sent POST to %s\n' %(resp.url))
resp.raise_for_status()
try:
results = resp.json()
print 'results =', str(results)
except:
print 'Non json resp is:', resp.text
sys.exit(1)
if isinstance(results, unicode) or isinstance(results, str):
print "repr(res.json)=> %s" % repr(results)
er = eval(results)
print type(er)
print json.dumps(er, sort_keys=True, indent=4)
sys.exit('Getting JavaScript string. Object expected.')
else:
print json.dumps(results, sort_keys=True, indent=4)