mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-15 09:26:43 +02:00
Improve list-news.ps1
This commit is contained in:
parent
f61d832ffa
commit
d9ce422619
@ -6,27 +6,25 @@
|
|||||||
.PARAMETER RSS_URL
|
.PARAMETER RSS_URL
|
||||||
Specifies the URL to the RSS feed
|
Specifies the URL to the RSS feed
|
||||||
.PARAMETER MaxCount
|
.PARAMETER MaxCount
|
||||||
Specifies the number of news to list
|
Specifies the number of lines to list (20 by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./list-news
|
PS> ./list-news
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz / License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$RSS_URL = "https://yahoo.com/news/rss/world", [int]$MaxCount = 20)
|
param([string]$RSS_URL = "https://yahoo.com/news/rss/world", [int]$MaxCount = 20)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
[xml]$Content = (invoke-webRequest -uri $RSS_URL -useBasicParsing).Content
|
[xml]$Content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content
|
||||||
"`n🌍 $($Content.rss.channel.title) 🌏"
|
[int]$Count = 1
|
||||||
|
|
||||||
[int]$Count = 0
|
|
||||||
foreach ($item in $Content.rss.channel.item) {
|
foreach ($item in $Content.rss.channel.item) {
|
||||||
"→ $($item.title)"
|
"→ $($item.title)"
|
||||||
$Count++
|
if ($Count++ -eq $MaxCount) { break }
|
||||||
if ($Count -eq $MaxCount) { break }
|
|
||||||
}
|
}
|
||||||
|
" Source: 🌍 $($Content.rss.channel.title) 🌍"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user