{{tag>PostgreSQL plpython INSPIRE SOAP species}} ====== Connaitre le code européen d'un taxon ====== **Merci à tous de partager les améliorations que vous apporteriez sur cette fonction** * Service SOAP utilisé : http://www.eu-nomen.eu/portal/soap.php * Conditions d'utilisation : non mentionnées par le fournisseur du service ==== Création de la fonction dans le schéma "outils" ==== CREATE OR REPLACE FUNCTION outils.eu_nomen_taxa_code("scientific_name" text) RETURNS text AS $BODY$ import urllib2; import httplib; from urllib import urlencode from urllib2 import Request, urlopen # définition de l'URL du service url = 'http://www.eu-nomen.eu/portal/soap.php' # les données SOAP à poster au service postdata=''+scientific_name+'' # l'entête headers = {'Content-Type': 'application/soap+xml; charset=utf-8','Content-Type': 'text/xml; charset=utf-8','Content-Length': str(len(postdata))} req = Request(url, postdata, headers) reponse = urlopen(req) text = reponse.read() rv = plpy.execute("SELECT ((xpath('//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getGUIDResponse/return/text()', '"+text+"'::xml, ARRAY[ARRAY['SOAP-ENV','http://schemas.xmlsoap.org/soap/envelope/'],ARRAY['SOAP-ENC','http://schemas.xmlsoap.org/soap/encoding/'],ARRAY['xsd','http://www.w3.org/2001/XMLSchema'],ARRAY['xsi','http://www.w3.org/2001/XMLSchema-instance'],ARRAY['ns1','http://PESI/v0.1']]))[1])::text AS code_taxon") eu_nomen_code = rv[0]['code_taxon'] return eu_nomen_code return text $BODY$ LANGUAGE plpythonu VOLATILE COST 100; ALTER FUNCTION outils.eu_nomen_taxa_code("scientific_name" text) OWNER TO dba; COMMENT ON function outils.eu_nomen_taxa_code("scientific_name" text) IS 'Retourne le code européen d''un taxon dont le nom d''espèce (sans auteur est passé en paramètre). Un grand merci à Dorian pour son micro cours sur SOAP!' ==== Utilisation ==== SELECT outils.eu_nomen_taxa_code('passer domestcus') Retourne : **[[http://www.eu-nomen.eu/portal/taxon.php?GUID=urn:lsid:faunaeur.org:taxname:97437|urn:lsid:faunaeur.org:taxname:97437]]**