Created
June 24, 2015 12:21
-
-
Save miguelius/cd3c34cf6229b5886863 to your computer and use it in GitHub Desktop.
gbif "client" apt for scripting
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
#!/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