Open adaniela opened 5 years ago
Query Species, ID Cites : 19 994 results
Columns: taxonRank idCITES nomSC
API Species, ID Cites:
Query Species, ID Cites and images: 31 306 results
Columns: idCITES item itemLabel taxonRank nomScientific taxonCommonName taxonCommonName_lang Image
API Species, ID Cites and images:
@adaniela a essayé d’utiliser l’api dans une web app rails sans succès pour le moment. Ci-dessous l'erreur que j'ai eu: "rails aborted! OpenURI::HTTPError: 403 Please identify your user agent, see https://meta.wikimedia.org/wiki/User-Agent_policy"
Entête pour la requête GET : User-Agent: EndangeredSpeciesIdentifier/0.1 (contact@okfnfr; http://cites.okfn.fr/en/home/)
requests
librarySee docs on the requests
library here
import requests
# Wikidata SPARQL endpoint
url = 'https://query.wikidata.org/sparql'
# build the SPARQL query string
sparql_string = '\
SELECT distinct ?taxonRank ?idCITES ?nomSc \
WHERE { \
?item wdt:P2040 ?idCITES . \
?item wdt:P225 ?nomSc . \
?item wdt:P105 ?taxonRank \
OPTIONAL { ?item wdt:P18 ?image . } \
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" } \
} \
LIMIT 20 \
'
# set custom header required by Wikidata service ; pass them in as a dict
# (optional? - the GET call seems to work from Python without this)
header ={'User-Agent':'EndangeredSpeciesIdentifier/0.1 (contact@okfnfr; http://cites.okfn.fr/en/home/)'}
# specify url parameters ; pass in as a dict
params = {'format':'json','query':sparql_string}
# make the HTTP GET call
r = requests.get(url, params=params, headers=header)
# examine the json returned
print( r.json() )
# display the results without the query metadata
print( r.json()['results']['bindings'] )
# display only the first result
print( r.json()['results']['bindings'][0] )
1er test: espèces et statut juridique CITES Species+ ID.