-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathNYTSemanticAPI.ps1
39 lines (29 loc) · 977 Bytes
/
NYTSemanticAPI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#requires -version 3
param($query = "Obama")
$apiKey = "e91adfa87e8f8026712c4d92b54a0b14:0:39364737"
function Get-SemanticNYT {
param($query)
$uri = "http://api.nytimes.com/svc/semantic/v2/"+
"concept/search.json?query=$query&api-key=$apiKey"
(Invoke-RestMethod $uri).results
}
function Get-SemanticNYTArticles {
param(
[Parameter(ValueFromPipelineByPropertyName=$true)]
$concept_name,
[Parameter(ValueFromPipelineByPropertyName=$true)]
$concept_type
)
process {
$uri = "http://api.nytimes.com/svc/semantic/v2/" +
"concept/name/$concept_type/$concept_name.json?&" +
"fields=all&api-key=$apiKey"
(Invoke-RestMethod $uri).results
}
}
Get-SemanticNYT $query |
Get-SemanticNYTArticles |
Where links |
Select -ExpandProperty article_list |
Select -ExpandProperty results |
Select date, title, url| Out-GridView