Last active
September 16, 2023 09:51
-
-
Save rewida17/d5ec23a4c453dfd81bd257416bc83abe to your computer and use it in GitHub Desktop.
Get latest news headers from news.ycombinator.com (top 5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
Author
rewida17
commented
Sep 16, 2023
- Grab data from "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
- Select top 5 items from list.
- Iterate over data from point 2
- Download JSON from "https://hacker-news.firebaseio.com/v0/item/{0}.json" where {0} is placeholder for news ID (Obtained in point 2)
- 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