Skip to content

Instantly share code, notes, and snippets.

@brantfaircloth
Created April 19, 2016 16:52
Show Gist options
  • Save brantfaircloth/63927c2df99dea44404fba69c922ce68 to your computer and use it in GitHub Desktop.
Save brantfaircloth/63927c2df99dea44404fba69c922ce68 to your computer and use it in GitHub Desktop.
fishbase 4
#!/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")
# get locality
my_request = requests.get(
'https://fishbase.ropensci.org/country',
params=payload
)
country_result = my_request.json()
country_codes = [item['C_Code'] for item in country_result['data']]
print("Country Names")
print("-" * 20)
for cc in country_codes:
payload = {
'C_Code': cc,
}
my_request = requests.get(
'https://fishbase.ropensci.org/countref',
params=payload
)
country_info = my_request.json()
print(country_info['data'][0]['PAESE'])
pdb.set_trace()
print("\n")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment