Extension:External Data/Web pages/examples
The following are example uses of the #get_web_data parser function (along with calls to #external_value and #for_external_table to display the information).
You can see these calls in action, with actual results, here.
IMDb
editRetrieve data from IMDb, the Internet Movie Database.
{{#get_web_data:url=https://imdb-api.com/en/API/Title/IMDB_KEY/tt0055630 |format=json |data=title=title,year=year,directors=directors,stars=stars}} Info for ID '''tt0055630''': * Name: {{#external_value:title}} * Year: {{#external_value:year}} * Director(s): {{#external_value:directors}} * Actors: {{#external_value:stars}}
or simply
{{#get_external_data:url=https://imdb-api.com/en/API/Title/IMDB_KEY/tt0055630}} Info for ID '''tt0055630''': * Name: {{#external_value:title}} * Year: {{#external_value:year}} * Director(s): {{#external_value:directors}} * Actors: {{#external_value:stars}}
You must also obtain an IMDb API key, and add the following to LocalSettings.php:
$wgExternalDataSources['imdb-api.com']['replacements'] = [
'IMDB_KEY'=> '...your key here...'
];
NCBI taxonomy
editRetrieve data from the National Center for Biotechnology Information.
{{#get_web_data:url=https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=taxonomy&rettype=fasta&retmode=xml&id=8371 |format=xml |data=ScientificName=ScientificName,CommonName=CommonName,Division=Division}} Information for taxon ID '''8371''': * Scientific name: {{#external_value:ScientificName}} * Common name: {{#external_value:CommonName}} * Division: {{#external_value:Division}}
or simply (note the lower case in variable names):
{{#get_external_data:url=https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=taxonomy&rettype=fasta&retmode=xml&id=8371}} Information for taxon ID '''8371''': * Scientific name: {{#external_value:scientificname}} * Common name: {{#external_value:commonname}} * Division: {{#external_value:division}}
PubMed
editRetrieve data from PubMed, run by the National Center for Biotechnology Information.
{{#get_web_data:url=https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=19782018&retmode=xml |format=xml |data=ArticleTitle=ArticleTitle,LastName=LastName,ForeName=ForeName,JournalTitle=Title,Year=Year,Volume=Volume}} Information for PMID '''19782018''': * Title: {{#external_value:ArticleTitle}} * Name: {{#external_value:LastName}}, {{#external_value:ForeName}} * Journal: {{#external_value:JournalTitle}} * Year: {{#external_value:Year}} * Volume: {{#external_value:Volume}}
Scopus
editRetrieve data from Elsevier's Scopus database.
{{#get_web_data: url=https://api.elsevier.com/content/search/scopus?query=DOI(10.1103/PhysRevA.20.1521)&apiKey=ELSEVIER_KEY |format=json |data=dc_title=dc:title,dc_creator=dc:creator,citedby-count=citedby-count}} Information for '''10.1103/PhysRevA.20.1521''': * Title: {{#external_value:dc_title}} * Author: {{#external_value:dc_creator}} * "Cited by" count: {{#external_value:citedby-count}}
You must also obtain an Elsevier API key, and add the following to LocalSettings.php:
$wgExternalDataSources['api.elsevier.com']['replacements'] = [
'ELSEVIER_KEY'=> '...your key here...'
];
Wikidata - individual entry
editSPARQL query:
SELECT ?item ?itemLabel ?symbol ?atomicNumber ( YEAR( ?discoveryDate ) AS ?discoveryYear ) ?discoverer ?discovererLabel WHERE { VALUES ?item { wd:Q654 } . ?item wdt:P246 ?symbol . ?item wdt:P1086 ?atomicNumber . ?item wdt:P575 ?discoveryDate . ?item wdt:P61 ?discoverer SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }
Actual wikitext (which includes this query):
{{#get_web_data:url=https://query.wikidata.org/sparql?query={{urlencode: SELECT ?item ?itemLabel ?symbol ?atomicNumber ( YEAR( ?discoveryDate ) AS ?discoveryYear ) ?discoverer ?discovererLabel WHERE { VALUES ?item { wd:Q654 } . ?item wdt:P246 ?symbol . ?item wdt:P1086 ?atomicNumber . ?item wdt:P575 ?discoveryDate . ?item wdt:P61 ?discoverer SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } }}&format=json |format=json |use jsonpath |data=itemLabel=$.results.bindings[0].itemLabel.value, symbol=$.results.bindings[0].symbol.value, atomicNumber=$.results.bindings[0].atomicNumber.value, discoveryYear=$.results.bindings[0].discoveryYear.value, discovererURL=$.results.bindings[*].discoverer.value, discovererLabel=$.results.bindings[*].discovererLabel.value, }} Info for '''Q654''': * Name: {{#external_value:itemLabel}} * Symbol: {{#external_value:symbol}} * Atomic number: {{#external_value:atomicNumber}} * Year discovered: {{#external_value:discoveryYear}} * Discoverers: {{#for_external_table:[{{{discovererURL}}} {{{discovererLabel}}}], <nowiki />}}
Wikidata - full query
editAll paintings that depict a squirrel.
SPARQL query:
SELECT DISTINCT ?painting ?paintingLabel ?creator ?creatorLabel ( YEAR( ?inception ) as ?year ) ?genre ?genreLabel ( SUBSTR( ?str_image, 52 ) AS ?fileName ) WHERE { ?painting wdt:P180 wd:Q9482 . ?painting wdt:P170 ?creator . ?painting wdt:P571 ?inception . ?painting wdt:P136 ?genre . ?painting wdt:P18 ?image . BIND (STR(?image) AS ?str_image) SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY ?paintingLabel
Actual wikitext (which includes this query):
{{#get_web_data:url=https://query.wikidata.org/sparql?query={{urlencode: SELECT DISTINCT ?painting ?paintingLabel ?creator ?creatorLabel ( YEAR( ?inception ) as ?year ) ?genre ?genreLabel ( SUBSTR( ?str_image, 52 ) AS ?fileName ) WHERE { ?painting wdt:P180 wd:Q9482 . ?painting wdt:P170 ?creator . ?painting wdt:P571 ?inception . ?painting wdt:P136 ?genre . ?painting wdt:P18 ?image . BIND (STR(?image) AS ?str_image) SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY ?paintingLabel }}&format=json |format=json |use jsonpath |data=paintingURL=$.results.bindings[*].painting.value, paintingLabel=$.results.bindings[*].paintingLabel.value, creatorURL=$.results.bindings[*].creator.value, creatorLabel=$.results.bindings[*].creatorLabel.value, year=$.results.bindings[*].year.value, genre=$.results.bindings[*].genreLabel.value, fileName=$.results.bindings[*].fileName.value }} {| class="wikitable" ! Name ! Artist ! Year ! Genre ! Image {{#for_external_table:<nowiki/> {{!}}- {{!}} [{{{paintingURL}}} {{{paintingLabel}}}] {{!}} [{{{creatorURL}}} {{{creatorLabel}}}] {{!}} {{{year}}} {{!}} {{{genre}}} {{!}} [[File:{{{fileName}}}|80px]] }} |}