Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Postgres Nomenklatura Client
CREATE OR REPLACE FUNCTION nomenklatura (key text, dataset text, api_key text)
RETURNS text
AS $$
import json, urllib, urllib2
url = 'http://nomenklatura.okfnlabs.org/%s/lookup?' % dataset
url += urllib.urlencode({'api_key': api_key, 'key': key})
req = urllib2.Request(url, None, {'Accept': 'application/json'})
try:
fh = urllib2.urlopen(req)
data = json.loads(fh.read())
if data.get('is_matched'):
return data.get('value').get('value')
except urllib2.HTTPError:
pass
return None
$$ LANGUAGE plpythonu;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.