#!/usr/bin/python from SOAPpy import WSDL import re import sys def get_Records(name, offset_number): a = wsdlObjectWoRMS.getAphiaRecords(name, like='true', fuzzy='true', marine_only='false', offset=offset_number) return(a) def process_worms_output(records): for b in records: record = str(b) t_family = re.compile("family': '[A-Z][a-z]+idae") m_family = t_family.search(record) if m_family: family = m_family.group().replace("family': '","") t_name = re.compile("scientificname': '[A-Z][a-z]+[ a-z]*") m_name = t_name.search(record) if m_name: name = m_name.group().replace("scientificname': '","") t_authority = re.compile("authority': '[\(\)A-Za-z ]+") m_authority = t_authority.search(record) if m_authority: authority = m_authority.group().replace("authority': '","") t_valid = re.compile("valid_name': '[\(\)A-Za-z ]+") m_valid = t_valid.search(record) if m_valid: valid = m_valid.group().replace("valid_name': '","") print '\n', name, authority print 'Accepted name:', valid print family else: print '\n', name, authority print 'Accepted name: None' print family def get_all_worms_records(taxon_name): start = 1 max_capacity = 50 records = [] print 'get_all_worms_records: fetching records', start, 'to', max_capacity, 'for taxon', taxon_name a = get_Records(str(taxon_name), start) if not a == None: for i in a: records.append(i) while len(records) == max_capacity: start = start + 50 max_capacity = max_capacity + 50 print 'get_all_worms_records: fetching records', start, 'to', max_capacity, 'for taxon', taxon_name b = get_Records(str(taxon_name), start) if not b == None: for i in b: records.append(i) print 'get_all_worms_records: returning', len(records), 'records for taxon', taxon_name process_worms_output(records) wsdlObjectWoRMS = WSDL.Proxy('https://ras.biodiversity.aq/aphia.php?p=soap&wsdl=1') if len(sys.argv) == 1: print ' USAGE: ./worms.py taxon_name1 taxon_name2 ... taxon_nameN' print ' EXAMPLE: ./worms.py Mytilus\ edulis Tellinidae' print ' ERROR: Enter one or more taxon names' target_names = sys.argv[1:] for a in target_names: get_all_worms_records(a) print '\n'
Since some users experienced issue while implementing the call 'matchAphiaRecordsByNames' with suds-py3, we have added another python example that covers this case. Enjoy!
from suds import null, WebFault from suds.client import Client cl = Client('https://ras.biodiversity.aq/aphia.php?p=soap&wsdl=1') scinames = cl.factory.create('scientificnames') scinames["_arrayType"] = "string[]" scinames["scientificname"] = ["Buccinum fusiforme", "Abra alba"] array_of_results_array = cl.service.matchAphiaRecordsByNames(scinames, like="true", fuzzy="false", marine_only="false") for results_array in array_of_results_array: for aphia_object in results_array: print('%s %s %s' % (aphia_object.AphiaID, aphia_object.scientificname, aphia_object.genus))