Updated list-news.ps1 and list-headlines.ps1

This commit is contained in:
Markus Fleschutz 2023-11-24 11:43:46 +01:00
parent eca81b91d5
commit 5ad06bb3d3
2 changed files with 16 additions and 17 deletions

View File

@ -2,11 +2,11 @@
.SYNOPSIS .SYNOPSIS
Lists the latest headlines Lists the latest headlines
.DESCRIPTION .DESCRIPTION
This PowerShell script lists the latest RSS feed news. This PowerShell script lists the latest headlines by using a RSS (Really Simple Syndication) feed.
.PARAMETER RSS_URL .PARAMETER RSS_URL
Specifies the URL to the RSS feed Specifies the URL to the RSS feed (Yahoo World News by default)
.PARAMETER maxCount .PARAMETER maxLines
Specifies the number of news to list Specifies the maximum number of lines to list (24 by default)
.EXAMPLE .EXAMPLE
PS> ./list-headlines.ps1 PS> ./list-headlines.ps1
Niger coup: Ecowas deadline sparks anxiety in northern Nigeria Niger coup: Ecowas deadline sparks anxiety in northern Nigeria
@ -17,18 +17,17 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$RSS_URL = "https://www.yahoo.com/news/rss", [int]$maxCount = 20) param([string]$RSS_URL = "https://news.yahoo.com/rss/world", [int]$maxLines = 24)
try { try {
[xml]$content = (Invoke-WebRequest -uri $RSS_URL -useBasicParsing).Content [xml]$content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content
[int]$count = 0 [int]$count = 1
foreach ($item in $content.rss.channel.item) { foreach ($item in $content.rss.channel.item) {
"❇️ $($item.title)" "❇️ $($item.title)"
$count++ if ($count++ -eq $maxLines) { break }
if ($count -eq $maxCount) { break }
} }
$source = $Content.rss.channel.title $source = $content.rss.channel.title
$date = $Content.rss.channel.pubDate $date = $content.rss.channel.pubDate
" (by $source as of $date)" " (by $source as of $date)"
exit 0 # success exit 0 # success
} catch { } catch {

View File

@ -1,10 +1,10 @@
<# <#
.SYNOPSIS .SYNOPSIS
List the latest news Lists the latest news
.DESCRIPTION .DESCRIPTION
This PowerShell script lists the latest news by using RSS (Really Simple Syndication) feeds. This PowerShell script lists the latest news by using a RSS (Really Simple Syndication) feed.
.PARAMETER RSS_URL .PARAMETER RSS_URL
Specifies the URL to the RSS feed (Yahoo News by default) Specifies the URL to the RSS feed (Yahoo World News by default)
.PARAMETER maxLines .PARAMETER maxLines
Specifies the maximum number of lines to list (24 by default) Specifies the maximum number of lines to list (24 by default)
.PARAMETER speed .PARAMETER speed
@ -19,7 +19,7 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$RSS_URL = "https://www.yahoo.com/news/rss", [int]$maxLines = 24, [int]$speed = 10) param([string]$RSS_URL = "https://news.yahoo.com/rss/world", [int]$maxLines = 24, [int]$speed = 10)
try { try {
[xml]$content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content [xml]$content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content
@ -28,8 +28,8 @@ try {
& "$PSScriptRoot/write-typewriter.ps1" "❇️ $($item.title)" $speed & "$PSScriptRoot/write-typewriter.ps1" "❇️ $($item.title)" $speed
if ($count++ -eq $maxLines) { break } if ($count++ -eq $maxLines) { break }
} }
$source = $Content.rss.channel.title $source = $content.rss.channel.title
$date = $Content.rss.channel.pubDate $date = $content.rss.channel.pubDate
" (by $source as of $date)" " (by $source as of $date)"
exit 0 # success exit 0 # success
} catch { } catch {