User:F705i

From Wikidata
Jump to navigation Jump to search

If you see Segoe UI on this page, your computer may be ready to run PowerShell scripts. With Windows PowerShell 3.0, creating a bot is as easy as shelling ps!

[System.Net.ServicePointManager]::Expect100Continue = $false
$uri = 'http://www.wikidata.org/w/api.php'
$useragent = 'PowerShell/3.0 (your@email.address)'
$q = [ordered]@{
    action = 'wbgetentities'
    ids = 'Q11198812'
    format = 'xml'
}
$responsexml = Invoke-RestMethod -Uri $uri -Body $q -UserAgent $useragent
$entity = $responsexml.SelectSingleNode('/api/entities/entity[1]')
$label = $entity.SelectSingleNode("labels/label[@language='en']/@value").Value
$description = $entity.SelectSingleNode("descriptions/description[@language='en']/@value").Value
Write-Host $label, 'is a', $description