Skip to content

Instantly share code, notes, and snippets.

@brantfaircloth
Created April 19, 2016 16:47
Show Gist options
  • Save brantfaircloth/547d65e46335b6c59f4eb5daed2498c8 to your computer and use it in GitHub Desktop.
Save brantfaircloth/547d65e46335b6c59f4eb5daed2498c8 to your computer and use it in GitHub Desktop.
fishbase 3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
(c) 2016 Brant Faircloth || http://faircloth-lab.org/
All rights reserved.
This code is distributed under a 3-clause BSD license. Please see
LICENSE.txt for more information.
Created on 19 April 2016 08:48 CDT (-0500)
"""
import requests
import pdb
def main():
# get information from species table (should contain species code)
payload = {
'genus': 'lepisosteus',
'species': 'osseus'
}
my_request = requests.get(
'https://fishbase.ropensci.org/species',
params=payload
)
species_result = my_request.json()
# get species code
my_species_code = species_result['data'][0]['SpecCode']
# get common name
# first we need species code
payload = {
'SpecCode': my_species_code,
}
my_request = requests.get(
'https://fishbase.ropensci.org/comnames',
params=payload
)
commnames_result = my_request.json()
print("Common Names")
print("-" * 20)
for name in commnames_result['data']:
print(name['ComName'])
print("\n")
# get predators
my_request = requests.get(
'https://fishbase.ropensci.org/predats',
params=payload
)
predats_result = my_request.json()
print("Predator Names")
print("-" * 20)
for name in predats_result['data']:
print(name['PredatorName'])
print("\n")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment