Skip to content

Instantly share code, notes, and snippets.

@miguelius
Created June 24, 2015 12:21
Show Gist options
  • Save miguelius/cd3c34cf6229b5886863 to your computer and use it in GitHub Desktop.
Save miguelius/cd3c34cf6229b5886863 to your computer and use it in GitHub Desktop.
gbif "client" apt for scripting
#!/usr/bin/env python
import urllib2, json, sys
def askGBIF(entity, entityId):
GBIF_GENERIC_WS="http://api.gbif.org/v1/%s/%s"
opener = urllib2.build_opener()
return (opener.open(GBIF_GENERIC_WS % (entity, entityId)))
def askGBIFasText(entity, entityId):
return askGBIF(entity, entityId).read()
if __name__ == "__main__":
try:
entity = sys.argv[1]
entityId = sys.argv[2]
print askGBIFasText(entity, entityId)
except IndexError:
print "usage: %s service uniqueId\n" % sys.argv[0]
print " service\toccurrence, organization, dataset, installation, etc"
print " uniqueId\tcorresponding entity's id"
except Exception as e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment