mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-16 09:56:40 +02:00
Improved watch-news.ps1
This commit is contained in:
parent
659807f16c
commit
cbf0c4ce14
@ -5,9 +5,11 @@
|
|||||||
This PowerShell script lists the latest headlines by using a RSS (Really Simple Syndication) feed.
|
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 (Yahoo World News by default)
|
Specifies the URL to the RSS feed (Yahoo World News by default)
|
||||||
|
.PARAMETER timeInterval
|
||||||
|
Specifies the time interval in millisec between the Web requests
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./watch-headlines.ps1
|
PS> ./watch-news.ps1
|
||||||
❇️ Niger coup: Ecowas deadline sparks anxiety in northern Nigeria ❇️
|
❇️ Niger coup: Ecowas deadline sparks anxiety in northern Nigeria ❇️
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -16,20 +18,26 @@
|
|||||||
|
|
||||||
param([string]$RSS_URL = "https://news.yahoo.com/rss/world", [int]$timeInterval = 30000) # in ms
|
param([string]$RSS_URL = "https://news.yahoo.com/rss/world", [int]$timeInterval = 30000) # in ms
|
||||||
|
|
||||||
function GetLatestHeadline {
|
function PrintLatestHeadlines([string]$previous, [int]$maxLines) {
|
||||||
[xml]$content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content
|
[xml]$content = (Invoke-WebRequest -URI $RSS_URL -useBasicParsing).Content
|
||||||
foreach ($item in $content.rss.channel.item) { return "$($item.title)" }
|
[string]$latest = ""
|
||||||
return ""
|
|
||||||
|
foreach ($item in $content.rss.channel.item) {
|
||||||
|
$itemTitle = "$($item.title)"
|
||||||
|
if ($latest -eq "") { $latest = $itemTitle }
|
||||||
|
if ($itemTitle -eq $previous) { break }
|
||||||
|
|
||||||
|
& "$PSScriptRoot/write-animated.ps1" "❇️ $itemTitle ❇️"
|
||||||
|
$maxLines--
|
||||||
|
if ($maxLines -eq 0) { break }
|
||||||
|
}
|
||||||
|
return $latest
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$previous = ""
|
$latest = ""
|
||||||
while ($true) {
|
while ($true) {
|
||||||
$latest = GetLatestHeadline
|
$latest = PrintLatestHeadlines $latest 10
|
||||||
if ($latest -ne $previous) {
|
|
||||||
& "$PSScriptRoot/write-animated.ps1" "❇️ $latest ❇️"
|
|
||||||
$previous = $latest
|
|
||||||
}
|
|
||||||
Start-Sleep -milliseconds $timeInterval
|
Start-Sleep -milliseconds $timeInterval
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
Loading…
x
Reference in New Issue
Block a user