Last active
May 1, 2018 02:44
-
-
Save nickynicolson/808ed3da1a7cbaa46134 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import urllib2 | |
try: | |
# Base url for the TNRS match_names API | |
url = 'http://api.opentreeoflife.org/v2/tnrs/match_names' | |
# Encode data value to be looked up as an array of names: | |
data = '{"names": ["'+value+'"]}' | |
print "Looking up: " + data | |
# Set HTTP headers: | |
headers = { 'Content-Type' : 'application/json' } | |
# Make the call using HTTP POST | |
req = urllib2.Request(url, data, headers) | |
response = urllib2.urlopen(req) | |
# Return the JSON value | |
return response.read() | |
except (Error): | |
print 'Exception occurred' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a Jython snippet that can be used for a column addition operation to call the OpenTreeOfLife TNRS API and store the JSON result.
It's a bit more complex than a regular OpenRefine column addition as the OpenTree API only responds to HTTP POST. OpenRefine's function to add a column by fetching URLs can only use HTTP GET.