Skip to content

Instantly share code, notes, and snippets.

@rewida17
Last active September 16, 2023 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rewida17/d5ec23a4c453dfd81bd257416bc83abe to your computer and use it in GitHub Desktop.
Save rewida17/d5ec23a4c453dfd81bd257416bc83abe to your computer and use it in GitHub Desktop.
Get latest news headers from news.ycombinator.com (top 5)
# For PowerShell 7+, because Foreach-Object -Parallel is used
# Based on https://github.com/HackerNews/API
#
function Get-YcombinatorFeed {
(Invoke-RestMethod -Method Get "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty") -as [array] |
Select-Object -First 5 | Foreach-Object -ThrottleLimit 5 -Parallel {
Invoke-RestMethod -Method Get ( "https://hacker-news.firebaseio.com/v0/item/{0}.json" -f $_ )
} | Format-Table -AutoSize title, url
}
# For PowerShell 5
function Get-YcombinatorFeed {
(Invoke-RestMethod -Method Get -UseBasicParsing "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty") -as [array] |
Select-Object -First 5 | Foreach-Object {
Invoke-RestMethod -UseBasicParsing -Method Get ( "https://hacker-news.firebaseio.com/v0/item/{0}.json" -f $_ )
} | Format-Table -AutoSize title, url
}
@rewida17
Copy link
Author

  1. Grab data from "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
  2. Select top 5 items from list.
  3. Iterate over data from point 2
  4. Download JSON from "https://hacker-news.firebaseio.com/v0/item/{0}.json" where {0} is placeholder for news ID (Obtained in point 2)
  5. Display as simple table with article title and URL on right side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment